Skip to content

Commit

Permalink
fix: use singular on function secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-s committed Aug 10, 2024
1 parent 9ce70dd commit 55e7055
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions internal/resources/resource_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"`
}

Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/single_function_with_secret/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "qernal_function" "function" {
weight = 100
}

secrets {
secret {
name = "ENV_VAR"
reference = var.secret_reference
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ resource "qernal_function" "function" {
weight = 100
}

secrets {
secret {
name = "ENV_VAR"
reference = data.qernal_secret_environment.env_secret.reference
}
Expand Down

0 comments on commit 55e7055

Please sign in to comment.