From ecb8d0e8141449879311d7ea4e6625d3ee3b80f2 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Tue, 14 May 2024 13:29:29 -0700 Subject: [PATCH 01/14] Fix deployment env vars throwing error when using secret --- docs/resources/deployment.md | 3 ++ .../datasources/data_source_deployment.go | 2 +- internal/provider/models/deployment.go | 30 +++++++++++++++++-- internal/provider/models/deployments.go | 2 +- .../provider/resources/resource_deployment.go | 25 +++++++++++----- .../resources/resource_deployment_test.go | 10 ++++++- internal/provider/schemas/deployment.go | 2 +- 7 files changed, 60 insertions(+), 14 deletions(-) diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md index 8d9d6b81..3bfe47e2 100644 --- a/docs/resources/deployment.md +++ b/docs/resources/deployment.md @@ -154,6 +154,9 @@ Required: - `is_secret` (Boolean) Whether Environment variable is a secret - `key` (String) Environment variable key + +Optional: + - `value` (String, Sensitive) Environment variable value Read-Only: diff --git a/internal/provider/datasources/data_source_deployment.go b/internal/provider/datasources/data_source_deployment.go index 675bf97d..980d9f40 100644 --- a/internal/provider/datasources/data_source_deployment.go +++ b/internal/provider/datasources/data_source_deployment.go @@ -106,7 +106,7 @@ func (d *deploymentDataSource) Read( } // Populate the model with the response data - diags := data.ReadFromResponse(ctx, deployment.JSON200, false) + diags := data.ReadFromResponse(ctx, deployment.JSON200, false, nil) if diags.HasError() { resp.Diagnostics.Append(diags...) return diff --git a/internal/provider/models/deployment.go b/internal/provider/models/deployment.go index 84af8a59..ab1f9239 100644 --- a/internal/provider/models/deployment.go +++ b/internal/provider/models/deployment.go @@ -4,6 +4,8 @@ import ( "context" "time" + "github.com/samber/lo" + "github.com/astronomer/terraform-provider-astro/internal/clients/platform" "github.com/astronomer/terraform-provider-astro/internal/provider/schemas" "github.com/astronomer/terraform-provider-astro/internal/utils" @@ -73,6 +75,7 @@ func (data *Deployment) ReadFromResponse( ctx context.Context, deployment *platform.Deployment, isResource bool, + requestEnvVars *[]platform.DeploymentEnvironmentVariableRequest, ) diag.Diagnostics { // Read common fields data.Id = types.StringValue(deployment.Id) @@ -116,7 +119,30 @@ func (data *Deployment) ReadFromResponse( data.ImageTag = types.StringValue(deployment.ImageTag) data.ImageRepository = types.StringValue(deployment.ImageRepository) data.ImageVersion = types.StringPointerValue(deployment.ImageVersion) - data.EnvironmentVariables, diags = utils.ObjectSet(ctx, deployment.EnvironmentVariables, schemas.DeploymentEnvironmentVariableAttributeTypes(), DeploymentEnvironmentVariableTypesObject) + + // Environment variables are a special case + // Since terraform wants to know the values of the secret values in the request at all times, and our API does not send back the secret values in the response + // We must use the request value and set it in the Terraform response to keep Terraform from emitting errors + // Since the value is marked as sensitive, Terraform will not output the actual value in the plan/apply output + envVars := *deployment.EnvironmentVariables + if requestEnvVars != nil && deployment.EnvironmentVariables != nil { + requestEnvVarsMap := lo.SliceToMap(*requestEnvVars, func(envVar platform.DeploymentEnvironmentVariableRequest) (string, platform.DeploymentEnvironmentVariable) { + return envVar.Key, platform.DeploymentEnvironmentVariable{ + Key: envVar.Key, + Value: envVar.Value, + IsSecret: envVar.IsSecret, + } + }) + for i, envVar := range envVars { + if envVar.IsSecret { + if requestEnvVar, ok := requestEnvVarsMap[envVar.Key]; ok { + // If the envVar has a secret value, update the value in the response + envVars[i].Value = requestEnvVar.Value + } + } + } + } + data.EnvironmentVariables, diags = utils.ObjectSet(ctx, &envVars, schemas.DeploymentEnvironmentVariableAttributeTypes(), DeploymentEnvironmentVariableTypesObject) if diags.HasError() { return diags } @@ -223,8 +249,8 @@ func DeploymentEnvironmentVariableTypesObject( ) (types.Object, diag.Diagnostics) { obj := DeploymentEnvironmentVariable{ Key: types.StringValue(envVar.Key), - Value: types.StringPointerValue(envVar.Value), UpdatedAt: types.StringValue(envVar.UpdatedAt), + Value: types.StringPointerValue(envVar.Value), IsSecret: types.BoolValue(envVar.IsSecret), } diff --git a/internal/provider/models/deployments.go b/internal/provider/models/deployments.go index dfe16f64..2f94426b 100644 --- a/internal/provider/models/deployments.go +++ b/internal/provider/models/deployments.go @@ -25,7 +25,7 @@ func (data *Deployments) ReadFromResponse( values := make([]attr.Value, len(deployments)) for i, deployment := range deployments { var singleDeploymentData Deployment - diags := singleDeploymentData.ReadFromResponse(ctx, &deployment, false) + diags := singleDeploymentData.ReadFromResponse(ctx, &deployment, false, nil) if diags.HasError() { return diags } diff --git a/internal/provider/resources/resource_deployment.go b/internal/provider/resources/resource_deployment.go index 2b191be0..8293b50d 100644 --- a/internal/provider/resources/resource_deployment.go +++ b/internal/provider/resources/resource_deployment.go @@ -120,6 +120,7 @@ func (r *DeploymentResource) Create( var diags diag.Diagnostics var createDeploymentRequest platform.CreateDeploymentRequest + var envVars []platform.DeploymentEnvironmentVariableRequest switch data.Type.ValueString() { case string(platform.DeploymentTypeSTANDARD): @@ -152,7 +153,7 @@ func (r *DeploymentResource) Create( } // env vars - envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + envVars, diags = RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -314,7 +315,7 @@ func (r *DeploymentResource) Create( return } - diags = data.ReadFromResponse(ctx, deployment.JSON200, true) + diags = data.ReadFromResponse(ctx, deployment.JSON200, true, &envVars) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -333,13 +334,20 @@ func (r *DeploymentResource) Read( ) { var data models.Deployment + tflog.Debug(ctx, fmt.Sprintf("reading a deployment resource")) + // Read Terraform prior state data into the model resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { return } + envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + if diags.HasError() { + resp.Diagnostics.Append(diags...) + return + } + // get request deployment, err := r.platformClient.GetDeploymentWithResponse( ctx, @@ -366,7 +374,7 @@ func (r *DeploymentResource) Read( return } - diags := data.ReadFromResponse(ctx, deployment.JSON200, true) + diags = data.ReadFromResponse(ctx, deployment.JSON200, true, &envVars) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -394,6 +402,7 @@ func (r *DeploymentResource) Update( // update request var diags diag.Diagnostics var updateDeploymentRequest platform.UpdateDeploymentRequest + var envVars []platform.DeploymentEnvironmentVariableRequest switch data.Type.ValueString() { case string(platform.DeploymentTypeSTANDARD): @@ -423,7 +432,7 @@ func (r *DeploymentResource) Update( } // env vars - envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + envVars, diags = RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -481,7 +490,7 @@ func (r *DeploymentResource) Update( } // env vars - envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + envVars, diags = RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -537,7 +546,7 @@ func (r *DeploymentResource) Update( } // env vars - envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + envVars, diags = RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -582,7 +591,7 @@ func (r *DeploymentResource) Update( return } - diags = data.ReadFromResponse(ctx, deployment.JSON200, true) + diags = data.ReadFromResponse(ctx, deployment.JSON200, true, &envVars) if diags.HasError() { resp.Diagnostics.Append(diags...) return diff --git a/internal/provider/resources/resource_deployment_test.go b/internal/provider/resources/resource_deployment_test.go index f535c95e..d153dabd 100644 --- a/internal/provider/resources/resource_deployment_test.go +++ b/internal/provider/resources/resource_deployment_test.go @@ -151,6 +151,7 @@ func TestAcc_ResourceDeploymentStandard(t *testing.T) { resource.TestCheckNoResourceAttr(awsResourceVar, "worker_queues"), resource.TestCheckResourceAttr(awsResourceVar, "scheduler_size", "SMALL"), resource.TestCheckResourceAttrSet(awsResourceVar, "environment_variables.0.key"), + resource.TestCheckResourceAttrSet(awsResourceVar, "environment_variables.1.key"), // Check via API that deployment exists testAccCheckDeploymentExistence(t, awsDeploymentName, true, true), ), @@ -222,12 +223,14 @@ func TestAcc_ResourceDeploymentStandard(t *testing.T) { CloudProvider: "AWS", Executor: "KUBERNETES", SchedulerSize: "SMALL", - IncludeEnvironmentVariables: false, + IncludeEnvironmentVariables: true, IsDevelopmentMode: false, }), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(awsResourceVar, "scheduler_size", "SMALL"), resource.TestCheckResourceAttr(awsResourceVar, "is_development_mode", "false"), + resource.TestCheckResourceAttrSet(awsResourceVar, "environment_variables.0.key"), + resource.TestCheckResourceAttrSet(awsResourceVar, "environment_variables.1.key"), // Check via API that deployment exists testAccCheckDeploymentExistence(t, awsDeploymentName, true, true), ), @@ -401,6 +404,11 @@ func envVarsStr(includeEnvVars bool) string { key = "key1" value = "value1" is_secret = false + }, + { + key = "key2" + value = "value2" + is_secret = true }]` } return fmt.Sprintf("environment_variables = %v", environmentVariables) diff --git a/internal/provider/schemas/deployment.go b/internal/provider/schemas/deployment.go index fc4da08d..14b772f4 100644 --- a/internal/provider/schemas/deployment.go +++ b/internal/provider/schemas/deployment.go @@ -586,7 +586,7 @@ func DeploymentEnvironmentVariableResourceAttributes() map[string]resourceSchema }, "value": resourceSchema.StringAttribute{ MarkdownDescription: "Environment variable value", - Required: true, + Optional: true, Sensitive: true, }, "updated_at": resourceSchema.StringAttribute{ From 9176733686c256f2dfd58e2ae9d7809634d016fd Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Tue, 14 May 2024 13:36:24 -0700 Subject: [PATCH 02/14] remove debug --- internal/provider/resources/resource_deployment.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/provider/resources/resource_deployment.go b/internal/provider/resources/resource_deployment.go index 8293b50d..e83c2b21 100644 --- a/internal/provider/resources/resource_deployment.go +++ b/internal/provider/resources/resource_deployment.go @@ -334,8 +334,6 @@ func (r *DeploymentResource) Read( ) { var data models.Deployment - tflog.Debug(ctx, fmt.Sprintf("reading a deployment resource")) - // Read Terraform prior state data into the model resp.Diagnostics.Append(req.State.Get(ctx, &data)...) if resp.Diagnostics.HasError() { From 5d1d2b495d35501b35854628d6e4c9cc667d8523 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Tue, 14 May 2024 15:21:00 -0700 Subject: [PATCH 03/14] fix bug --- internal/provider/resources/resource_deployment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/provider/resources/resource_deployment.go b/internal/provider/resources/resource_deployment.go index e83c2b21..8f30189a 100644 --- a/internal/provider/resources/resource_deployment.go +++ b/internal/provider/resources/resource_deployment.go @@ -213,7 +213,7 @@ func (r *DeploymentResource) Create( } // env vars - envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + envVars, diags = RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) if diags.HasError() { resp.Diagnostics.Append(diags...) return @@ -271,7 +271,7 @@ func (r *DeploymentResource) Create( } // env vars - envVars, diags := RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) + envVars, diags = RequestDeploymentEnvironmentVariables(ctx, data.EnvironmentVariables) if diags.HasError() { resp.Diagnostics.Append(diags...) return From 032a415ab9287e9378edbb096eb369a0c5eec620 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Tue, 14 May 2024 22:41:28 -0700 Subject: [PATCH 04/14] test --- internal/provider/resources/resource_deployment_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/provider/resources/resource_deployment_test.go b/internal/provider/resources/resource_deployment_test.go index d153dabd..73b981ae 100644 --- a/internal/provider/resources/resource_deployment_test.go +++ b/internal/provider/resources/resource_deployment_test.go @@ -240,7 +240,7 @@ func TestAcc_ResourceDeploymentStandard(t *testing.T) { ResourceName: awsResourceVar, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"external_ips"}, + ImportStateVerifyIgnore: []string{"external_ips", "environment_variables.1.value"}, // environment_variables.1.value is a secret value }, }, }) @@ -282,7 +282,7 @@ func TestAcc_ResourceDeploymentStandard(t *testing.T) { ResourceName: azureCeleryResourceVar, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"external_ips", "oidc_issuer_url"}, + ImportStateVerifyIgnore: []string{"external_ips", "oidc_issuer_url", "environment_variables.1.value"}, // environment_variables.0.value is a secret value }, }, }) @@ -324,7 +324,7 @@ func TestAcc_ResourceDeploymentStandard(t *testing.T) { ResourceName: gcpKubernetesResourceVar, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"external_ips", "oidc_issuer_url"}, + ImportStateVerifyIgnore: []string{"external_ips", "oidc_issuer_url", "environment_variables.1.value"}, // environment_variables.0.value is a secret value }, }, }) From bfc8701fbfa783e4f500cd3a24c5e20070de8f33 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:39:28 -0700 Subject: [PATCH 05/14] update gh action --- .github/workflows/testacc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index df454711..b0c9600d 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -69,7 +69,7 @@ jobs: "internal/provider/resources/resource_deployment.go" ) for file in "${FILES_TO_CHECK[@]}"; do - if git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep -q "$file"; then + if git diff --name-only origin/${{ github.base_ref }} origin/${{ github.head_ref }} | grep -q "$file"; then SKIP_TESTS="False" break fi From c94f86e43af19ca8811358dc501a60ff74172619 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:41:13 -0700 Subject: [PATCH 06/14] try to fix gh action --- .github/workflows/testacc.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index b0c9600d..e521d835 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -45,6 +45,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 + with: + fetch-depth: 0 # Fetch all history for all tags and branches - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: go-version-file: 'go.mod' @@ -69,7 +71,7 @@ jobs: "internal/provider/resources/resource_deployment.go" ) for file in "${FILES_TO_CHECK[@]}"; do - if git diff --name-only origin/${{ github.base_ref }} origin/${{ github.head_ref }} | grep -q "$file"; then + if git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep -q "$file"; then SKIP_TESTS="False" break fi From e259c0612f47643ff87d314c397526ffb9376e2b Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:46:00 -0700 Subject: [PATCH 07/14] fix gh action --- .github/workflows/testacc.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index e521d835..a2b7582c 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -45,8 +45,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 - with: - fetch-depth: 0 # Fetch all history for all tags and branches + - name: Set up git main branch + if: github.ref != 'refs/heads/main' + run: git rev-parse --verify main || git remote set-branches origin main && git fetch --depth 1 origin main && git branch main origin/main - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: go-version-file: 'go.mod' From c16db5d89db33606755ff5a0d70a0753dc2ccc5a Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:50:00 -0700 Subject: [PATCH 08/14] try again gh action --- .github/workflows/testacc.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index a2b7582c..0cf0e6e9 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -45,9 +45,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 - - name: Set up git main branch - if: github.ref != 'refs/heads/main' - run: git rev-parse --verify main || git remote set-branches origin main && git fetch --depth 1 origin main && git branch main origin/main + with: + fetch-depth: 0 - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: go-version-file: 'go.mod' From e65b6d5164bb77692a4a8f75a8f06a94be97b9dc Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:53:07 -0700 Subject: [PATCH 09/14] try again gh action --- .github/workflows/testacc.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 0cf0e6e9..48ad1f8e 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -45,8 +45,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 - with: - fetch-depth: 0 - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: go-version-file: 'go.mod' @@ -59,6 +57,7 @@ jobs: - name: Determine if expensive tests should run if: github.event_name == 'pull_request' run: | + git fetch --all echo "CHECKING FILES FOR SKIP LOGIC..." SKIP_TESTS="True" FILES_TO_CHECK=( From e91b23da7777bbabdc6ea7ea0afba22c61b48e6b Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:55:53 -0700 Subject: [PATCH 10/14] try again gh action --- .github/workflows/testacc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 48ad1f8e..427ded5f 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -70,7 +70,7 @@ jobs: "internal/provider/resources/resource_deployment.go" ) for file in "${FILES_TO_CHECK[@]}"; do - if git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep -q "$file"; then + if git diff --name-only remotes/origin/${{ github.base_ref }} remotes/origin/${{ github.head_ref }} | grep -q "$file"; then SKIP_TESTS="False" break fi From 162247ad8b1c73b9498b411b417ef39823388ef5 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 00:58:50 -0700 Subject: [PATCH 11/14] add comment to gh action --- .github/workflows/testacc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 427ded5f..734e82e8 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -75,6 +75,7 @@ jobs: break fi done + echo "SKIP_CLUSTER_RESOURCE_TESTS=$SKIP_TESTS" echo "SKIP_CLUSTER_RESOURCE_TESTS=$SKIP_TESTS" >> $GITHUB_ENV - env: TF_ACC: "1" From 7a195afad1bccb242eecc0c4a8926773d8b21745 Mon Sep 17 00:00:00 2001 From: Vandy Liu <33995460+vandyliu@users.noreply.github.com> Date: Wed, 15 May 2024 10:09:53 -0700 Subject: [PATCH 12/14] Update internal/provider/resources/resource_deployment.go --- .../provider/resources/resource_deployment.go | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/internal/provider/resources/resource_deployment.go b/internal/provider/resources/resource_deployment.go index 309e5a0e..7a61ba5a 100644 --- a/internal/provider/resources/resource_deployment.go +++ b/internal/provider/resources/resource_deployment.go @@ -91,32 +91,6 @@ func (r *DeploymentResource) Create( return } - deploymentOptions, err := r.platformClient.GetDeploymentOptionsWithResponse(ctx, r.organizationId, &platform.GetDeploymentOptionsParams{ - DeploymentType: lo.ToPtr(platform.GetDeploymentOptionsParamsDeploymentType(data.Type.ValueString())), - Executor: lo.ToPtr(platform.GetDeploymentOptionsParamsExecutor(data.Executor.ValueString())), - CloudProvider: lo.ToPtr(platform.GetDeploymentOptionsParamsCloudProvider(data.CloudProvider.ValueString())), - }) - if err != nil { - tflog.Error(ctx, "failed to get deployment options", map[string]interface{}{"error": err}) - resp.Diagnostics.AddError( - "Client Error", - fmt.Sprintf("Unable to get deployment options for deployment creation, got error: %s", err), - ) - return - } - _, diagnostic := clients.NormalizeAPIError(ctx, deploymentOptions.HTTPResponse, deploymentOptions.Body) - if diagnostic != nil { - resp.Diagnostics.Append(diagnostic) - return - } - if deploymentOptions.JSON200 == nil || len(deploymentOptions.JSON200.RuntimeReleases) == 0 { - resp.Diagnostics.AddError( - "Client Error", - "Unable to get runtime releases for deployment creation, got empty runtime releases", - ) - return - } - var diags diag.Diagnostics var createDeploymentRequest platform.CreateDeploymentRequest var envVars []platform.DeploymentEnvironmentVariableRequest From 941974e0f7ba52e61b9d68a8b94b0b70a223580e Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 10:10:57 -0700 Subject: [PATCH 13/14] resource deployment --- internal/provider/resources/resource_deployment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/resources/resource_deployment.go b/internal/provider/resources/resource_deployment.go index 7a61ba5a..25360b98 100644 --- a/internal/provider/resources/resource_deployment.go +++ b/internal/provider/resources/resource_deployment.go @@ -293,7 +293,7 @@ func (r *DeploymentResource) Create( ) return } - _, diagnostic = clients.NormalizeAPIError(ctx, deployment.HTTPResponse, deployment.Body) + _, diagnostic := clients.NormalizeAPIError(ctx, deployment.HTTPResponse, deployment.Body) if diagnostic != nil { resp.Diagnostics.Append(diagnostic) return From 544111821d3f98eec6b3d475d4c901c7790cfd53 Mon Sep 17 00:00:00 2001 From: Vandy Liu Date: Wed, 15 May 2024 18:34:11 -0700 Subject: [PATCH 14/14] add missing return statements --- internal/provider/resources/resource_cluster.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/provider/resources/resource_cluster.go b/internal/provider/resources/resource_cluster.go index cbd5e4c4..0295b7d6 100644 --- a/internal/provider/resources/resource_cluster.go +++ b/internal/provider/resources/resource_cluster.go @@ -228,6 +228,7 @@ func (r *ClusterResource) Create( readyCluster, err := stateConf.WaitForStateContext(ctx) if err != nil { resp.Diagnostics.AddError("Cluster creation failed", err.Error()) + return } diags = data.ReadFromResponse(ctx, readyCluster.(*platform.Cluster)) @@ -381,6 +382,7 @@ func (r *ClusterResource) Update( readyCluster, err := stateConf.WaitForStateContext(ctx) if err != nil { resp.Diagnostics.AddError("Cluster update failed", err.Error()) + return } diags = data.ReadFromResponse(ctx, readyCluster.(*platform.Cluster)) @@ -451,6 +453,7 @@ func (r *ClusterResource) Delete( _, err = stateConf.WaitForStateContext(ctx) if err != nil { resp.Diagnostics.AddError("Cluster deletion failed", err.Error()) + return } tflog.Trace(ctx, fmt.Sprintf("deleted a cluster resource: %v", data.Id.ValueString()))