From 55e7055a6d54f25ac91bf6c0740fc01029b2d6c1 Mon Sep 17 00:00:00 2001 From: Andrew Seymour Date: Sat, 10 Aug 2024 23:11:19 +0000 Subject: [PATCH] fix: use singular on function secrets --- internal/resources/resource_function.go | 20 +++++++++---------- tests/helpers.go | 2 +- .../single_function_with_secret/main.tf | 2 +- .../main.tf | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/resources/resource_function.go b/internal/resources/resource_function.go index 3209f29..64613fe 100644 --- a/internal/resources/resource_function.go +++ b/internal/resources/resource_function.go @@ -136,7 +136,7 @@ func (r *FunctionResource) Schema(_ context.Context, _ resource.SchemaRequest, r }, }, }, - "secrets": schema.ListNestedBlock{ + "secret": schema.ListNestedBlock{ Description: "secrets to be use dby the function", NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ @@ -258,7 +258,7 @@ func (r *FunctionResource) Create(ctx context.Context, req resource.CreateReques functionSize := openapiclient.NewFunctionSize(int32(plan.Size.CPU.ValueInt64()), int32(plan.Size.Memory.ValueInt64())) functionRoutes := RoutesToOpenAPI(plan.Route) functionDeployment := DeploymentsToOepnAPI(plan.Deployment) - functionSecrets := SecretsToOpenAPI(plan.Secrets) + functionSecrets := SecretsToOpenAPI(plan.Secret) if functionSecrets == nil { functionSecrets = []openapiclient.FunctionEnv{} } @@ -315,9 +315,9 @@ func (r *FunctionResource) Create(ctx context.Context, req resource.CreateReques plan.Compliance = OpenAPIToCompliance(ctx, function.Compliance) if len(function.Secrets) == 0 { - plan.Secrets = nil + plan.Secret = nil } else { - plan.Secrets = FunctionEnvsToSecrets(ctx, function.Secrets) + plan.Secret = FunctionEnvsToSecrets(ctx, function.Secrets) } // Set state to fully populated data @@ -372,9 +372,9 @@ func (r *FunctionResource) Read(ctx context.Context, req resource.ReadRequest, r state.Compliance = OpenAPIToCompliance(ctx, function.Compliance) if len(function.Secrets) == 0 { - state.Secrets = nil + state.Secret = nil } else { - state.Secrets = FunctionEnvsToSecrets(ctx, function.Secrets) + state.Secret = FunctionEnvsToSecrets(ctx, function.Secrets) } // Set refreshed state @@ -430,7 +430,7 @@ func (r *FunctionResource) Update(ctx context.Context, req resource.UpdateReques functionDeployments = append(functionDeployments, openAPIdeploy) } - functionSecrets := SecretsToOpenAPI(plan.Secrets) + functionSecrets := SecretsToOpenAPI(plan.Secret) // Always send an empty array to the API if there are no secrets if functionSecrets == nil { functionSecrets = []openapiclient.FunctionEnv{} @@ -503,9 +503,9 @@ func (r *FunctionResource) Update(ctx context.Context, req resource.UpdateReques plan.Compliance = OpenAPIToCompliance(ctx, function.Compliance) if len(function.Secrets) == 0 { - plan.Secrets = nil + plan.Secret = nil } else { - plan.Secrets = FunctionEnvsToSecrets(ctx, function.Secrets) + plan.Secret = FunctionEnvsToSecrets(ctx, function.Secrets) } diags = resp.State.Set(ctx, plan) @@ -551,7 +551,7 @@ type FunctionResourceModel struct { Route []Route `tfsdk:"route"` Scaling Scaling `tfsdk:"scaling"` Deployment []Deployment `tfsdk:"deployment"` - Secrets []Secret `tfsdk:"secrets"` + Secret []Secret `tfsdk:"secret"` Compliance []types.String `tfsdk:"compliance"` } diff --git a/tests/helpers.go b/tests/helpers.go index 12b2b27..4bde944 100644 --- a/tests/helpers.go +++ b/tests/helpers.go @@ -222,7 +222,7 @@ func createSecretEnv(projid string, secretname string) (string, string, error) { func randomSecretName() string { const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - b := make([]byte, 4) + b := make([]byte, 8) for i := range b { b[i] = charset[math_rand.Intn(len(charset))] } diff --git a/tests/modules/single_function_with_secret/main.tf b/tests/modules/single_function_with_secret/main.tf index 746afc2..7227a71 100644 --- a/tests/modules/single_function_with_secret/main.tf +++ b/tests/modules/single_function_with_secret/main.tf @@ -45,7 +45,7 @@ resource "qernal_function" "function" { weight = 100 } - secrets { + secret { name = "ENV_VAR" reference = var.secret_reference } diff --git a/tests/modules/single_function_with_secret_datasource/main.tf b/tests/modules/single_function_with_secret_datasource/main.tf index d49f311..40b7888 100644 --- a/tests/modules/single_function_with_secret_datasource/main.tf +++ b/tests/modules/single_function_with_secret_datasource/main.tf @@ -50,7 +50,7 @@ resource "qernal_function" "function" { weight = 100 } - secrets { + secret { name = "ENV_VAR" reference = data.qernal_secret_environment.env_secret.reference }