Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Org certificate library #962

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/904.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:feature
`resource/cloudavenue_org_certificate_library` - Added new resource to manage certificate in the Cloud Avenue Organization.
```

```release-note:feature
`datasource/cloudavenue_org_certificate_library` - Added new datasource to get certificate information in the Cloud Avenue Organization.
```
31 changes: 31 additions & 0 deletions docs/data-sources/org_certificate_library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
page_title: "cloudavenue_org_certificate_library Data Source - cloudavenue"
subcategory: "Organization"
description: |-
The cloudavenue_org_certificate_library data source allows you to retrieve information about an certificate in your organization's library.
---

# cloudavenue_org_certificate_library (Data Source)

The `cloudavenue_org_certificate_library` data source allows you to retrieve information about an certificate in your organization's library.

## Example Usage

```terraform
data "cloudavenue_org_certificate_library" "example" {
name = "my-certificate-library"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) The ID of the certificate library. Ensure that one and only one attribute from this collection is set : `name`, `id`.
- `name` (String) The name of the certificate library. Ensure that one and only one attribute from this collection is set : `name`, `id`.

### Read-Only

- `certificate` (String) The certificate content. It can be a PEM encoded certificate or a certificate chain.
- `description` (String) The description of the certificate library.
46 changes: 46 additions & 0 deletions docs/resources/org_certificate_library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
page_title: "cloudavenue_org_certificate_library Resource - cloudavenue"
subcategory: "Organization"
description: |-
The cloudavenue_org_certificate_library resource allows you to manage certificate in your organization's library.
---

# cloudavenue_org_certificate_library (Resource)

The `cloudavenue_org_certificate_library` resource allows you to manage certificate in your organization's library.

## Example Usage

```terraform
resource "cloudavenue_org_certificate_library" "example" {
name = "company-certificate"
description = "dev environment certificate"
certificate = chomp(file("/my/certificate/path/cert.pem"))
private_key = chomp(file("/my/certificate/path/key.pem"))
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `certificate` (String) (ForceNew) The certificate content. It can be a PEM encoded certificate or a certificate chain. Contains all strings including the BEGIN CERTIFICATE and END CERTIFICATE lines. No empty lines are allowed.
- `name` (String) The name of the certificate library.

### Optional

- `description` (String) The description of the certificate library.
- `passphrase` (String, Sensitive) (ForceNew) The passphrase of the private key.
- `private_key` (String, Sensitive) (ForceNew) The private key of the certificate in PEM format.

### Read-Only

- `id` (String) The ID of the certificate library.

## Import

Import is supported using the following syntax:
```shell
terraform import cloudavenue_org_certificate_library.example nameOrID
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "cloudavenue_org_certificate_library" "example" {
name = "my-certificate-library"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import cloudavenue_org_certificate_library.example nameOrID
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "cloudavenue_org_certificate_library" "example" {
name = "company-certificate"
description = "dev environment certificate"
certificate = chomp(file("/my/certificate/path/cert.pem"))
private_key = chomp(file("/my/certificate/path/key.pem"))
}
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ toolchain go1.23.3

require (
github.com/FrangipaneTeam/terraform-analytic-tool v0.0.12
github.com/FrangipaneTeam/terraform-plugin-framework-superschema v1.8.1
github.com/FrangipaneTeam/terraform-plugin-framework-supertypes v0.4.0
github.com/aws/aws-sdk-go v1.55.6
github.com/drhodes/golorem v0.0.0-20220328165741-da82e5b29246
github.com/google/uuid v1.6.0
Expand All @@ -21,7 +19,8 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/iancoleman/strcase v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.20.1
github.com/madflojo/testcerts v1.4.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.1
github.com/orange-cloudavenue/common-go/print v0.0.0-20250109171729-2be550d5d3ac
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339
github.com/orange-cloudavenue/terraform-plugin-framework-planmodifiers v1.4.0
Expand Down Expand Up @@ -65,7 +64,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.24.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-resty/resty/v2 v2.16.3 // indirect
github.com/go-resty/resty/v2 v2.16.5 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/FrangipaneTeam/terraform-analytic-tool v0.0.12 h1:rbh0EtyILnuyu07RuOhrEVXXXRcrxSvKSVtOO14h5ok=
github.com/FrangipaneTeam/terraform-analytic-tool v0.0.12/go.mod h1:j3TxedNm9WrKKseOSBKxnNtquuXa0FQChO/QdcvPKtg=
github.com/FrangipaneTeam/terraform-plugin-framework-superschema v1.8.1 h1:ov6LOLLANE9nZVQ1DrpMLuITkejMzTbZLE54xtxZ14A=
github.com/FrangipaneTeam/terraform-plugin-framework-superschema v1.8.1/go.mod h1:AkcBw7L/PhgCm1A4P4adGrbEjE7i2maeCn/Jeh5t5Lo=
github.com/FrangipaneTeam/terraform-plugin-framework-supertypes v0.4.0 h1:5lFfjKOhBxBQNwQ63PZWBc5Unqgi5ppYq9RDoN05N+k=
github.com/FrangipaneTeam/terraform-plugin-framework-supertypes v0.4.0/go.mod h1:klzXBi/0nMGXBh4bzRjP2wef+HE6rfCMia81Glc2+eY=
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down Expand Up @@ -103,8 +99,8 @@ github.com/go-playground/validator/v10 v10.24.0 h1:KHQckvo8G6hlWnrPX4NJJ+aBfWNAE
github.com/go-playground/validator/v10 v10.24.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-resty/resty/v2 v2.16.3 h1:zacNT7lt4b8M/io2Ahj6yPypL7bqx9n1iprfQuodV+E=
github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
Expand Down Expand Up @@ -221,6 +217,8 @@ github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4F
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/madflojo/testcerts v1.4.0 h1:I09gN0C1ly9IgeVNcAqKk8RAKIJTe3QnFrrPBDyvzN4=
github.com/madflojo/testcerts v1.4.0/go.mod h1:MW8sh39gLnkKh4K0Nc55AyHEDl9l/FBLDUsQhpmkuo0=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
Expand Down Expand Up @@ -262,8 +260,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.20.1 h1:5oJ/xg5q+USbwKDkDGpIAyB4hyYiNBECHJyrtVY8wAQ=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.20.1/go.mod h1:flkZyfFFO60w78vhTackWb1FxoEm5EVA8yakrrJRN1I=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.1 h1:Uy/AkLQM/KQzDMFBCVR7vh4BppgROa/GK5UNfXbP7e0=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.1/go.mod h1:1jc0W7Me1Oq0kSPoJNYcH6emJ5HruIIsh1//Wp26AJQ=
github.com/orange-cloudavenue/common-go/print v0.0.0-20250109171729-2be550d5d3ac h1:f1Fd70+PMDTK6FE4gHdNfoHSQHLn5pfJMTjZPzOWZtc=
github.com/orange-cloudavenue/common-go/print v0.0.0-20250109171729-2be550d5d3ac/go.mod h1:IYtCusqpEGS0dhC6F8X9GHrrt1gp1zHaNhSKGYV59Xg=
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339 h1:DEKcWLGbEhu/I6kn9NAXhVCFrbPhR+Ef7oLmpLVnnPM=
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/alb/service_engine_group_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package alb
import (
"context"

superschema "github.com/orange-cloudavenue/terraform-plugin-framework-superschema"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"

superschema "github.com/FrangipaneTeam/terraform-plugin-framework-superschema"
)

func serviceEngineGroupSchema(_ context.Context) superschema.Schema {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/alb/service_engine_group_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package alb

import (
supertypes "github.com/FrangipaneTeam/terraform-plugin-framework-supertypes"
supertypes "github.com/orange-cloudavenue/terraform-plugin-framework-supertypes"
)

type serviceEngineGroupModel struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/alb/service_engine_groups_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package alb
import (
"context"

superschema "github.com/orange-cloudavenue/terraform-plugin-framework-superschema"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"

superschema "github.com/FrangipaneTeam/terraform-plugin-framework-superschema"
)

func serviceEngineGroupsSchema(ctx context.Context) superschema.Schema {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/alb/service_engine_groups_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package alb

import supertypes "github.com/FrangipaneTeam/terraform-plugin-framework-supertypes"
import supertypes "github.com/orange-cloudavenue/terraform-plugin-framework-supertypes"

type serviceEngineGroupsModel struct {
ID supertypes.StringValue `tfsdk:"id"`
Expand Down
74 changes: 42 additions & 32 deletions internal/provider/org/certificate_library_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"

"github.com/orange-cloudavenue/cloudavenue-sdk-go/v1/org"

"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/metrics"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/org"
)

var (
Expand All @@ -24,18 +25,21 @@ func NewCertificateLibraryDatasource() datasource.DataSource {
}

type CertificateLibraryDatasource struct {
client *client.CloudAvenue
org org.Org
client *client.CloudAvenue
orgClient *org.Client
}

// Init Initializes the data source.
func (d *CertificateLibraryDatasource) Init(ctx context.Context, dm *CertificateLibraryDatasourcesGoModel) (diags diag.Diagnostics) {
// Uncomment the following lines if you need to access to the Org
d.org, diags = org.Init(d.client)
if diags.HasError() {
return
func (d *CertificateLibraryDatasource) Init(ctx context.Context, dm *CertificateLibraryDatasourceModel) (diags diag.Diagnostics) {
var err error

org, err := d.client.CAVSDK.V1.Org()
if err != nil {
diags.AddError("Error initializing ORG client", err.Error())
}

d.orgClient = org.Client

return
}

Expand All @@ -44,7 +48,7 @@ func (d *CertificateLibraryDatasource) Metadata(ctx context.Context, req datasou
}

func (d *CertificateLibraryDatasource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = certificateLibraryDatasourceSchema(ctx).GetDataSource(ctx)
resp.Schema = certificateLibrarySchema(ctx).GetDataSource(ctx)
}

func (d *CertificateLibraryDatasource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
Expand All @@ -67,10 +71,7 @@ func (d *CertificateLibraryDatasource) Configure(ctx context.Context, req dataso
func (d *CertificateLibraryDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
defer metrics.New("data.cloudavenue_org_certificate_library", d.client.GetOrgName(), metrics.Read)()

config := &CertificateLibraryDatasourcesGoModel{}

// If the data source don't have same schema/structure as the resource, you can use the following code:
// config := &CertificateLibraryDatasourceModel{}
config := &CertificateLibraryDatasourceModel{}

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, config)...)
Expand All @@ -88,23 +89,32 @@ func (d *CertificateLibraryDatasource) Read(ctx context.Context, req datasource.
Implement the data source read logic here.
*/

// If read function is identical to the resource, you can use the following code:
/*
s := &CertificateLibraryDatasourcesGoResource{
client: d.client,
// org: d.org,
// vdc: d.vdc,
// vapp: d.vapp,
}

// Read data from the API
data, _, diags := s.read(ctx, config)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
*/
s := &CertificateLibraryResource{
client: d.client,
orgClient: d.orgClient,
}

configResource := &CertificateLibraryModel{
ID: config.ID,
Name: config.Name,
}

// Read data from the API
data, found, diags := s.read(ctx, configResource)
if !found {
resp.Diagnostics.AddError("Resource not found", fmt.Sprintf("The Certificate %s(%s) was not found", config.Name.Get(), config.ID.Get()))
return
}
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

config.ID.Set(data.ID.Get())
config.Name.Set(data.Name.Get())
config.Description.Set(data.Description.Get())
config.Certificate.Set(data.Certificate.Get())

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &config)...)
}
Loading
Loading