Skip to content

Commit

Permalink
feat: comments resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
marnas committed Dec 4, 2024
1 parent aee2e28 commit caee6f2
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 28 deletions.
37 changes: 32 additions & 5 deletions docs/resources/gateway_service_account_v2.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "conduktor_gateway_service_account_v2 Resource - conduktor"
subcategory: ""
page_title: "Conduktor : conduktor_gateway_service_account_v2 "
subcategory: "gateway/v2"
description: |-
Resource for managing Conduktor Gateway Service Accounts.
This resource allows you to create, read, update and delete service accounts in Conduktor Gateway.
---

# conduktor_gateway_service_account_v2 (Resource)
# conduktor_gateway_service_account_v2

Resource for managing Conduktor service accounts.
This resource allows you to create, read, update and delete service accounts in Conduktor Gateway.

## Example Usage

### Simple service account of LOCAL type and without a vCluster
```terraform
resource "conduktor_gateway_service_account_v2" "local_sa" {
name = "simple-service-account"
spec {
type = "LOCAL"
}
}
```

### Complex service account of EXTERNAL type with expernal names and a vCluster
```terraform
resource "conduktor_gateway_service_account_v2" "external_sa" {
name = "complex-service-account"
vcluster = "vcluster_sa"
spec {
type = "EXTERNAL"
external_names = ["externalName"]
}
}
```


<!-- schema generated by tfplugindocs -->
Expand All @@ -34,3 +58,6 @@ Required:
Optional:

- `external_names` (Set of String) Set of the external names of the service account. Required if spec.type is set to EXTERNAL. At the moment, an external service account should have exactly one external name (The support for many external names will be available soon)



Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "conduktor_gateway_service_account_v2" "example" {
name = "complex-service-account"
# vcluster = "vcluster1"
resource "conduktor_gateway_service_account_v2" "external_sa" {
name = "complex-service-account"
vcluster = "vcluster_sa"
spec {
type = "EXTERNAL"
external_names = ["externalName"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "conduktor_gateway_service_account_v2" "example" {
resource "conduktor_gateway_service_account_v2" "local_sa" {
name = "simple-service-account"
spec {
type = "LOCAL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func InternalModelToTerraform(ctx context.Context, r *model.GatewayServiceAccoun
return gwserviceaccounts.GatewayServiceAccountV2Model{}, mapper.WrapDiagError(diag, "external_names", mapper.IntoTerraform)
}

// specValue := gwserviceaccounts.SpecValue{
// SpecType: schema.NewStringValue(r.Spec.Type),
// ExternalNames: externalNamesList,
// }

specValue, diag := gwserviceaccounts.NewSpecValue(
map[string]attr.Type{
"type": basetypes.StringType{},
Expand Down
2 changes: 1 addition & 1 deletion internal/model/gateway_service_account_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type GatewayServiceAccountMetadata struct {
}

func (r GatewayServiceAccountMetadata) String() string {
return fmt.Sprintf(`name: %s`, r.Name)
return fmt.Sprintf(`name: %s, vCluster: %s`, r.Name, r.VCluster)
}

type GatewayServiceAccountSpec struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/gateway_service_account_v2_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *GatewayServiceAccountV2Resource) Create(ctx context.Context, req resour
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, fmt.Sprintf("Create service accouunt named %s", data.Name.String()))
tflog.Info(ctx, fmt.Sprintf("Create service account named %s", data.Name.String()))
tflog.Trace(ctx, fmt.Sprintf("Create service account with TF data: %+v", data))

gatewayResource, err := mapper.TFToInternalModel(ctx, &data)
Expand Down
21 changes: 10 additions & 11 deletions internal/provider/gateway_service_account_v2_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccGatewayServiceAccountV2Resource(t *testing.T) {
Config: providerConfig + test.TestAccTestdata(t, "gateway_service_account_v2_resource_create.tf"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceRef, "name", "user1"),
resource.TestCheckResourceAttr(resourceRef, "vcluster", "passthrough"),
resource.TestCheckResourceAttr(resourceRef, "vcluster", "vcluster_sa"),
resource.TestCheckResourceAttr(resourceRef, "spec.type", "EXTERNAL"),
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.#", "1"),
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.0", "externalName"),
Expand All @@ -39,7 +39,7 @@ func TestAccGatewayServiceAccountV2Resource(t *testing.T) {
Config: providerConfig + test.TestAccTestdata(t, "gateway_service_account_v2_resource_update.tf"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceRef, "name", "user1"),
resource.TestCheckResourceAttr(resourceRef, "vcluster", "passthrough"),
resource.TestCheckResourceAttr(resourceRef, "vcluster", "vcluster_sa"),
resource.TestCheckResourceAttr(resourceRef, "spec.type", "EXTERNAL"),
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.#", "1"),
resource.TestCheckResourceAttr(resourceRef, "spec.external_names.0", "newExternalName"),
Expand Down Expand Up @@ -81,21 +81,20 @@ func TestAccGatewayServiceAccountV2ExampleResource(t *testing.T) {
{
Config: providerConfig + test.TestAccExample(t, "resources", "conduktor_gateway_service_account_v2", "simple.tf"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "name", "simple-service-account"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "vcluster", "passthrough"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.type", "LOCAL"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.local_sa", "name", "simple-service-account"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.local_sa", "vcluster", "passthrough"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.local_sa", "spec.type", "LOCAL"),
),
},
// Create and Read from complex example
{
Config: providerConfig + test.TestAccExample(t, "resources", "conduktor_gateway_service_account_v2", "complex.tf"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "name", "complex-service-account"),
// TODO: Add vcluster tests - Needs gateway_vclusters to be deployed by terraform
// resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "vcluster", "vcluster1"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.type", "EXTERNAL"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.external_names.#", "1"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.example", "spec.external_names.0", "externalName"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.external_sa", "name", "complex-service-account"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.external_sa", "vcluster", "vcluster_sa"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.external_sa", "spec.type", "EXTERNAL"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.external_sa", "spec.external_names.#", "1"),
resource.TestCheckResourceAttr("conduktor_gateway_service_account_v2.external_sa", "spec.external_names.0", "externalName"),
),
},
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

resource "conduktor_gateway_service_account_v2" "test" {
name = "user1"
name = "user1"
vcluster = "vcluster_sa"
spec {
type = "EXTERNAL"
external_names = ["externalName"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

resource "conduktor_gateway_service_account_v2" "test" {
name = "user1"
name = "user1"
vcluster = "vcluster_sa"
spec {
type = "EXTERNAL"
external_names = ["newExternalName"]
Expand Down
4 changes: 2 additions & 2 deletions provider_code_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@
"path": "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
}
],
"schema_definition": "stringvalidator.RegexMatches(regexp.MustCompile(\"^[0-9a-z\\\\_\\\\-.]+$\"), \"\")"
"schema_definition": "stringvalidator.RegexMatches(regexp.MustCompile(\"^[a-zA-Z0-9_-]{3,64}$\"), \"\")"
}
}
]
Expand Down Expand Up @@ -1360,7 +1360,7 @@
"path": "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
}
],
"schema_definition": "stringvalidator.RegexMatches(regexp.MustCompile(\"^[0-9a-z\\\\_\\\\-.]+$\"), \"\")"
"schema_definition": "stringvalidator.RegexMatches(regexp.MustCompile(\"^[a-zA-Z0-9_-]+$\"), \"\")"
}
}
]
Expand Down
23 changes: 23 additions & 0 deletions templates/resources/gateway_service_account_v2.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
page_title: "Conduktor : conduktor_gateway_service_account_v2 "
subcategory: "gateway/v2"
description: |-
Resource for managing Conduktor Gateway Service Accounts.
This resource allows you to create, read, update and delete service accounts in Conduktor Gateway.
---

# {{ .Name }}

Resource for managing Conduktor service accounts.
This resource allows you to create, read, update and delete service accounts in Conduktor Gateway.

## Example Usage

### Simple service account of LOCAL type and without a vCluster
{{tffile "examples/resources/conduktor_gateway_service_account_v2/simple.tf"}}

### Complex service account of EXTERNAL type with expernal names and a vCluster
{{tffile "examples/resources/conduktor_gateway_service_account_v2/complex.tf"}}


{{ .SchemaMarkdown }}
7 changes: 7 additions & 0 deletions testdata/init/init.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Init manifests are used to initialize Console with the necessary resources using CLI.
---
apiVersion: gateway/v2
kind: VirtualCluster
metadata:
name: "vcluster_sa"
spec:
aclEnabled: false # defaults to false

0 comments on commit caee6f2

Please sign in to comment.