From 87e96488cbfd26904fb31821e706c47c9b383afe Mon Sep 17 00:00:00 2001 From: David Szabo Date: Mon, 29 Jan 2024 17:55:32 +0100 Subject: [PATCH] CDPCP-11100 Make polling optional for environment and datalake resource creations --- resources/datalake/common_schema.go | 10 +++++++++ resources/datalake/resource_aws_datalake.go | 16 ++++++++------ resources/datalake/resource_azure_datalake.go | 16 ++++++++------ resources/datalake/resource_gcp_datalake.go | 16 ++++++++------ resources/datalake/schema_aws_datalake.go | 10 +++++++++ resources/datalake/schema_azure_datalake.go | 10 +++++++++ resources/environments/converter_gcp.go | 6 +----- .../environments/environment_action_util.go | 21 ++++++++++++------- .../environments/resource_aws_environment.go | 19 ++++++++++------- .../resource_azure_environment.go | 18 +++++++++------- .../resource_azure_environment_test.go | 3 +++ .../environments/resource_gcp_environment.go | 13 +++++++++--- .../environments/schema_aws_environment.go | 9 ++++++++ .../environments/schema_azure_environment.go | 10 +++++++++ .../environments/schema_gcp_environment.go | 11 ++++++++++ utils/schema_extensions.go | 1 + 16 files changed, 139 insertions(+), 50 deletions(-) diff --git a/resources/datalake/common_schema.go b/resources/datalake/common_schema.go index 2319805c..717e0afd 100644 --- a/resources/datalake/common_schema.go +++ b/resources/datalake/common_schema.go @@ -12,6 +12,7 @@ package datalake import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -30,6 +31,15 @@ var generalAttributes = map[string]schema.Attribute{ MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.", Optional: true, Attributes: map[string]schema.Attribute{ + "async": schema.BoolAttribute{ + MarkdownDescription: "Boolean value that specifies if Terraform should wait for resource creation/deletion.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "polling_timeout": schema.Int64Attribute{ MarkdownDescription: "Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.", Default: int64default.StaticInt64(60), diff --git a/resources/datalake/resource_aws_datalake.go b/resources/datalake/resource_aws_datalake.go index 5421d4cb..8da62ffd 100644 --- a/resources/datalake/resource_aws_datalake.go +++ b/resources/datalake/resource_aws_datalake.go @@ -133,9 +133,11 @@ func (r *awsDatalakeResource) Create(ctx context.Context, req resource.CreateReq return } - if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { - utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") - return + if !state.PollingOptions.Async.ValueBool() { + if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { + utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") + return + } } descParams := operations.NewDescribeDatalakeParamsWithContext(ctx) @@ -404,9 +406,11 @@ func (r *awsDatalakeResource) Delete(ctx context.Context, req resource.DeleteReq return } - if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { - utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete AWS Datalake") - return + if !state.PollingOptions.Async.ValueBool() { + if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { + utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete AWS Datalake") + return + } } } diff --git a/resources/datalake/resource_azure_datalake.go b/resources/datalake/resource_azure_datalake.go index bfbb2482..0496379d 100644 --- a/resources/datalake/resource_azure_datalake.go +++ b/resources/datalake/resource_azure_datalake.go @@ -121,9 +121,11 @@ func (r *azureDatalakeResource) Create(ctx context.Context, req resource.CreateR return } - if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { - utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create Azure Datalake") - return + if !state.PollingOptions.Async.ValueBool() { + if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { + utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") + return + } } descParams := operations.NewDescribeDatalakeParamsWithContext(ctx) @@ -359,8 +361,10 @@ func (r *azureDatalakeResource) Delete(ctx context.Context, req resource.DeleteR return } - if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { - utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete Azure Datalake") - return + if !state.PollingOptions.Async.ValueBool() { + if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { + utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete Azure Datalake") + return + } } } diff --git a/resources/datalake/resource_gcp_datalake.go b/resources/datalake/resource_gcp_datalake.go index bbfc40f5..2d309c93 100644 --- a/resources/datalake/resource_gcp_datalake.go +++ b/resources/datalake/resource_gcp_datalake.go @@ -71,9 +71,11 @@ func (r *gcpDatalakeResource) Create(ctx context.Context, req resource.CreateReq return } - if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { - utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create GCP Datalake") - return + if !state.PollingOptions.Async.ValueBool() { + if err := waitForDatalakeToBeRunning(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { + utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "create AWS Datalake") + return + } } descParams := operations.NewDescribeDatalakeParamsWithContext(ctx) @@ -163,8 +165,10 @@ func (r *gcpDatalakeResource) Delete(ctx context.Context, req resource.DeleteReq return } - if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { - utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete GCP Datalake") - return + if !state.PollingOptions.Async.ValueBool() { + if err := waitForDatalakeToBeDeleted(ctx, state.DatalakeName.ValueString(), time.Hour, r.client.Datalake, state.PollingOptions); err != nil { + utils.AddDatalakeDiagnosticsError(err, &resp.Diagnostics, "delete GCP Datalake") + return + } } } diff --git a/resources/datalake/schema_aws_datalake.go b/resources/datalake/schema_aws_datalake.go index cf3639ed..3ffe56ac 100644 --- a/resources/datalake/schema_aws_datalake.go +++ b/resources/datalake/schema_aws_datalake.go @@ -12,6 +12,7 @@ package datalake import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" @@ -35,6 +36,15 @@ var awsDatalakeResourceSchema = schema.Schema{ MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.", Optional: true, Attributes: map[string]schema.Attribute{ + "async": schema.BoolAttribute{ + MarkdownDescription: "Boolean value that specifies if Terraform should wait for resource creation/deletion.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "polling_timeout": schema.Int64Attribute{ MarkdownDescription: "Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.", Default: int64default.StaticInt64(60), diff --git a/resources/datalake/schema_azure_datalake.go b/resources/datalake/schema_azure_datalake.go index 172f394b..f1fc642a 100644 --- a/resources/datalake/schema_azure_datalake.go +++ b/resources/datalake/schema_azure_datalake.go @@ -12,6 +12,7 @@ package datalake import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" @@ -35,6 +36,15 @@ var azureDatalakeResourceSchema = schema.Schema{ MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.", Optional: true, Attributes: map[string]schema.Attribute{ + "async": schema.BoolAttribute{ + MarkdownDescription: "Boolean value that specifies if Terraform should wait for resource creation/deletion.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "polling_timeout": schema.Int64Attribute{ MarkdownDescription: "Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.", Default: int64default.StaticInt64(60), diff --git a/resources/environments/converter_gcp.go b/resources/environments/converter_gcp.go index 986aca34..b119e836 100644 --- a/resources/environments/converter_gcp.go +++ b/resources/environments/converter_gcp.go @@ -141,12 +141,8 @@ func toGcpEnvironmentResource(ctx context.Context, env *environmentsmodels.Envir model.StatusReason = types.StringValue(env.StatusReason) tflog.Info(ctx, "about to convert tags.") if env.Tags != nil { - merged := env.Tags.Defaults - for k, v := range env.Tags.UserDefined { - merged[k] = v - } var tagDiags diag.Diagnostics - tagMap, tagDiags := types.MapValueFrom(ctx, types.StringType, merged) + tagMap, tagDiags := types.MapValueFrom(ctx, types.StringType, env.Tags.UserDefined) diags.Append(tagDiags...) model.Tags = tagMap } diff --git a/resources/environments/environment_action_util.go b/resources/environments/environment_action_util.go index cfe60c67..8190eb81 100644 --- a/resources/environments/environment_action_util.go +++ b/resources/environments/environment_action_util.go @@ -14,7 +14,9 @@ import ( "context" "time" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/cdp" @@ -28,7 +30,7 @@ const ( timeoutOneHour = time.Hour * 1 ) -func describeEnvironmentWithDiagnosticHandle(envName string, id string, ctx context.Context, client *cdp.Client, resp *resource.ReadResponse) (*environmentsmodels.Environment, error) { +func describeEnvironmentWithDiagnosticHandle(envName string, id string, ctx context.Context, client *cdp.Client, diags *diag.Diagnostics, state *tfsdk.State) (*environmentsmodels.Environment, error) { tflog.Info(ctx, "About to describe environment '"+envName+"'.") params := operations.NewDescribeEnvironmentParamsWithContext(ctx) params.WithInput(&environmentsmodels.DescribeEnvironmentRequest{ @@ -38,20 +40,20 @@ func describeEnvironmentWithDiagnosticHandle(envName string, id string, ctx cont if err != nil { tflog.Warn(ctx, "Something happened during environment fetch: "+err.Error()) if isEnvNotFoundError(err) { - resp.Diagnostics.AddWarning("Resource not found on provider", "Environment not found, removing from state.") + diags.AddWarning("Resource not found on provider", "Environment not found, removing from state.") tflog.Warn(ctx, "Environment not found, removing from state", map[string]interface{}{ "id": id, }) - resp.State.RemoveResource(ctx) + state.RemoveResource(ctx) return nil, err } - utils.AddEnvironmentDiagnosticsError(err, &resp.Diagnostics, "read Environment") + utils.AddEnvironmentDiagnosticsError(err, diags, "read Environment") return nil, err } return utils.LogEnvironmentSilently(ctx, descEnvResp.GetPayload().Environment, describeLogPrefix), nil } -func deleteEnvironmentWithDiagnosticHandle(environmentName string, ctx context.Context, client *cdp.Client, resp *resource.DeleteResponse, pollingTimeout *utils.PollingOptions) error { +func deleteEnvironmentWithDiagnosticHandle(environmentName string, ctx context.Context, client *cdp.Client, resp *resource.DeleteResponse, pollingOptions *utils.PollingOptions) error { params := operations.NewDeleteEnvironmentParamsWithContext(ctx) params.WithInput(&environmentsmodels.DeleteEnvironmentRequest{EnvironmentName: &environmentName}) _, err := client.Environments.Operations.DeleteEnvironment(params) @@ -60,7 +62,10 @@ func deleteEnvironmentWithDiagnosticHandle(environmentName string, ctx context.C return err } - err = waitForEnvironmentToBeDeleted(environmentName, timeoutOneHour, client.Environments, ctx, pollingTimeout) + if pollingOptions.Async.ValueBool() { + return nil + } + err = waitForEnvironmentToBeDeleted(environmentName, timeoutOneHour, client.Environments, ctx, pollingOptions) if err != nil { utils.AddEnvironmentDiagnosticsError(err, &resp.Diagnostics, "delete Environment") return err @@ -77,7 +82,7 @@ func isEnvNotFoundError(err error) bool { return false } -func waitForCreateEnvironmentWithDiagnosticHandle(ctx context.Context, client *cdp.Client, id string, envName string, resp *resource.CreateResponse, options *utils.PollingOptions) (*operations.DescribeEnvironmentOK, error) { +func waitForCreateEnvironmentWithDiagnosticHandle(ctx context.Context, client *cdp.Client, id string, envName string, resp *resource.CreateResponse, options *utils.PollingOptions) (*environmentsmodels.Environment, error) { if err := waitForEnvironmentToBeAvailable(id, timeoutOneHour, client.Environments, ctx, options); err != nil { utils.AddEnvironmentDiagnosticsError(err, &resp.Diagnostics, "create Environment failed") return nil, err @@ -101,5 +106,5 @@ func waitForCreateEnvironmentWithDiagnosticHandle(ctx context.Context, client *c utils.AddEnvironmentDiagnosticsError(err, &resp.Diagnostics, "create Environment failed") return nil, err } - return descEnvResp, nil + return descEnvResp.GetPayload().Environment, nil } diff --git a/resources/environments/resource_aws_environment.go b/resources/environments/resource_aws_environment.go index 2c7abfc2..6736efd1 100644 --- a/resources/environments/resource_aws_environment.go +++ b/resources/environments/resource_aws_environment.go @@ -12,6 +12,7 @@ package environments import ( "context" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" @@ -76,12 +77,18 @@ func (r *awsEnvironmentResource) Create(ctx context.Context, req resource.Create return } - descEnvResp, err := waitForCreateEnvironmentWithDiagnosticHandle(ctx, r.client, data.ID.ValueString(), data.EnvironmentName.ValueString(), resp, data.PollingOptions) + descEnvResp, err := describeEnvironmentWithDiagnosticHandle(data.EnvironmentName.ValueString(), data.ID.ValueString(), ctx, r.client, &resp.Diagnostics, &resp.State) if err != nil { return } + if !data.PollingOptions.Async.ValueBool() { + descEnvResp, err = waitForCreateEnvironmentWithDiagnosticHandle(ctx, r.client, data.ID.ValueString(), data.EnvironmentName.ValueString(), resp, data.PollingOptions) + if err != nil { + return + } + } - toAwsEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, descEnvResp.GetPayload().Environment, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics) + toAwsEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, descEnvResp, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics) diags = resp.State.Set(ctx, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -97,7 +104,7 @@ func (r *awsEnvironmentResource) Read(ctx context.Context, req resource.ReadRequ return } - env, err := describeEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.ID.ValueString(), ctx, r.client, resp) + env, err := describeEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.ID.ValueString(), ctx, r.client, &resp.Diagnostics, &resp.State) if err != nil { return } @@ -203,12 +210,8 @@ func toAwsEnvironmentResource(ctx context.Context, env *environmentsmodels.Envir model.Status = types.StringPointerValue(env.Status) model.StatusReason = types.StringValue(env.StatusReason) if env.Tags != nil { - merged := env.Tags.Defaults - for k, v := range env.Tags.UserDefined { - merged[k] = v - } var tagDiags diag.Diagnostics - tagMap, tagDiags := types.MapValueFrom(ctx, types.StringType, merged) + tagMap, tagDiags := types.MapValueFrom(ctx, types.StringType, env.Tags.UserDefined) diags.Append(tagDiags...) model.Tags = tagMap } diff --git a/resources/environments/resource_azure_environment.go b/resources/environments/resource_azure_environment.go index e6408c30..52b4f689 100644 --- a/resources/environments/resource_azure_environment.go +++ b/resources/environments/resource_azure_environment.go @@ -78,12 +78,18 @@ func (r *azureEnvironmentResource) Create(ctx context.Context, req resource.Crea return } - descEnvResp, err := waitForCreateEnvironmentWithDiagnosticHandle(ctx, r.client, data.ID.ValueString(), data.EnvironmentName.ValueString(), resp, data.PollingOptions) + descEnvResp, err := describeEnvironmentWithDiagnosticHandle(data.EnvironmentName.ValueString(), data.ID.ValueString(), ctx, r.client, &resp.Diagnostics, &resp.State) if err != nil { return } + if !data.PollingOptions.Async.ValueBool() { + descEnvResp, err = waitForCreateEnvironmentWithDiagnosticHandle(ctx, r.client, data.ID.ValueString(), data.EnvironmentName.ValueString(), resp, data.PollingOptions) + if err != nil { + return + } + } - toAzureEnvironmentResource(ctx, descEnvResp.GetPayload().Environment, &data, data.PollingOptions, &resp.Diagnostics) + toAzureEnvironmentResource(ctx, descEnvResp, &data, data.PollingOptions, &resp.Diagnostics) diags = resp.State.Set(ctx, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -99,7 +105,7 @@ func (r *azureEnvironmentResource) Read(ctx context.Context, req resource.ReadRe return } - descEnvResp, err := describeEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.ID.ValueString(), ctx, r.client, resp) + descEnvResp, err := describeEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.ID.ValueString(), ctx, r.client, &resp.Diagnostics, &resp.State) if err != nil { return } @@ -210,11 +216,7 @@ func toAzureEnvironmentResource(ctx context.Context, env *environmentsmodels.Env model.Status = types.StringPointerValue(env.Status) model.StatusReason = types.StringValue(env.StatusReason) if env.Tags != nil { - merged := env.Tags.Defaults - for k, v := range env.Tags.UserDefined { - merged[k] = v - } - tagMap, tagDiags := types.MapValueFrom(ctx, types.StringType, merged) + tagMap, tagDiags := types.MapValueFrom(ctx, types.StringType, env.Tags.UserDefined) diags.Append(tagDiags...) model.Tags = tagMap } diff --git a/resources/environments/resource_azure_environment_test.go b/resources/environments/resource_azure_environment_test.go index 3cc2394c..5c05940c 100644 --- a/resources/environments/resource_azure_environment_test.go +++ b/resources/environments/resource_azure_environment_test.go @@ -34,6 +34,7 @@ func createRawAzureEnvironmentResource() tftypes.Value { "crn": tftypes.String, "polling_options": tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ + "async": tftypes.Bool, "polling_timeout": tftypes.Number, }, }, @@ -118,9 +119,11 @@ func createRawAzureEnvironmentResource() tftypes.Value { "crn": tftypes.NewValue(tftypes.String, ""), "polling_options": tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ + "async": tftypes.Bool, "polling_timeout": tftypes.Number, }, }, map[string]tftypes.Value{ + "async": tftypes.NewValue(tftypes.Bool, false), "polling_timeout": tftypes.NewValue(tftypes.Number, 100), }), "status_reason": tftypes.NewValue(tftypes.String, ""), diff --git a/resources/environments/resource_gcp_environment.go b/resources/environments/resource_gcp_environment.go index 6b8d1e66..a98fe68c 100644 --- a/resources/environments/resource_gcp_environment.go +++ b/resources/environments/resource_gcp_environment.go @@ -12,6 +12,7 @@ package environments import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -70,12 +71,18 @@ func (r *gcpEnvironmentResource) Create(ctx context.Context, req resource.Create return } - descEnvResp, err := waitForCreateEnvironmentWithDiagnosticHandle(ctx, r.client, data.ID.ValueString(), data.EnvironmentName.ValueString(), resp, data.PollingOptions) + descEnvResp, err := describeEnvironmentWithDiagnosticHandle(data.EnvironmentName.ValueString(), data.ID.ValueString(), ctx, r.client, &resp.Diagnostics, &resp.State) if err != nil { return } + if !data.PollingOptions.Async.ValueBool() { + descEnvResp, err = waitForCreateEnvironmentWithDiagnosticHandle(ctx, r.client, data.ID.ValueString(), data.EnvironmentName.ValueString(), resp, data.PollingOptions) + if err != nil { + return + } + } - toGcpEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, descEnvResp.GetPayload().Environment, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics) + toGcpEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, descEnvResp, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics) diags = resp.State.Set(ctx, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -91,7 +98,7 @@ func (r *gcpEnvironmentResource) Read(ctx context.Context, req resource.ReadRequ return } - descEnvResp, err := describeEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.ID.ValueString(), ctx, r.client, resp) + descEnvResp, err := describeEnvironmentWithDiagnosticHandle(state.EnvironmentName.ValueString(), state.ID.ValueString(), ctx, r.client, &resp.Diagnostics, &resp.State) if err != nil { return } diff --git a/resources/environments/schema_aws_environment.go b/resources/environments/schema_aws_environment.go index bb402aca..c421a798 100644 --- a/resources/environments/schema_aws_environment.go +++ b/resources/environments/schema_aws_environment.go @@ -48,6 +48,15 @@ var AwsEnvironmentSchema = schema.Schema{ MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.", Optional: true, Attributes: map[string]schema.Attribute{ + "async": schema.BoolAttribute{ + MarkdownDescription: "Boolean value that specifies if Terraform should wait for resource creation/deletion.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "polling_timeout": schema.Int64Attribute{ MarkdownDescription: "Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.", Default: int64default.StaticInt64(60), diff --git a/resources/environments/schema_azure_environment.go b/resources/environments/schema_azure_environment.go index d988c2ce..fedfc263 100644 --- a/resources/environments/schema_azure_environment.go +++ b/resources/environments/schema_azure_environment.go @@ -13,6 +13,7 @@ package environments import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -49,6 +50,15 @@ var AzureEnvironmentSchema = schema.Schema{ MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.", Optional: true, Attributes: map[string]schema.Attribute{ + "async": schema.BoolAttribute{ + MarkdownDescription: "Boolean value that specifies if Terraform should wait for resource creation/deletion.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "polling_timeout": schema.Int64Attribute{ MarkdownDescription: "Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.", Default: int64default.StaticInt64(60), diff --git a/resources/environments/schema_gcp_environment.go b/resources/environments/schema_gcp_environment.go index 048461b4..96de4bef 100644 --- a/resources/environments/schema_gcp_environment.go +++ b/resources/environments/schema_gcp_environment.go @@ -12,8 +12,10 @@ package environments import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" @@ -37,6 +39,15 @@ func (r *gcpEnvironmentResource) Schema(_ context.Context, _ resource.SchemaRequ MarkdownDescription: "Polling related configuration options that could specify various values that will be used during CDP resource creation.", Optional: true, Attributes: map[string]schema.Attribute{ + "async": schema.BoolAttribute{ + MarkdownDescription: "Boolean value that specifies if Terraform should wait for resource creation/deletion.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "polling_timeout": schema.Int64Attribute{ MarkdownDescription: "Timeout value in minutes that specifies for how long should the polling go for resource creation/deletion.", Default: int64default.StaticInt64(60), diff --git a/utils/schema_extensions.go b/utils/schema_extensions.go index ac4ccf72..60430798 100644 --- a/utils/schema_extensions.go +++ b/utils/schema_extensions.go @@ -13,5 +13,6 @@ package utils import "github.com/hashicorp/terraform-plugin-framework/types" type PollingOptions struct { + Async types.Bool `tfsdk:"async"` PollingTimeout types.Int64 `tfsdk:"polling_timeout"` }