From 0f352cd69d2252543a637994b4732b041e5c204c Mon Sep 17 00:00:00 2001 From: Dean Huynh Date: Wed, 6 Mar 2024 15:07:40 -0800 Subject: [PATCH] Ensure created resources are tainted properly upon failed applies (#99) --- CHANGELOG.md | 3 +++ internal/provider/destination_filter_resource.go | 2 ++ internal/provider/destination_resource.go | 1 + internal/provider/destination_subscription_resource.go | 2 ++ internal/provider/function_resource.go | 2 ++ internal/provider/insert_function_instance_resource.go | 2 ++ internal/provider/profiles_warehouse_resource.go | 3 +++ internal/provider/reverse_etl_model_resource.go | 2 ++ internal/provider/tracking_plan_resource.go | 2 ++ internal/provider/transformation_resource.go | 2 ++ internal/provider/user_resource.go | 3 +++ internal/provider/warehouse_resource.go | 2 ++ 12 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ded072..13447c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.10.3 (March 6, 2024) +Correctly taints resources upon failed create to ensure resources are not duplicated. + ## 0.10.2 (March 6, 2024) Fixes a rendering bug for `segment_profiles_warehouse` resource docs. diff --git a/internal/provider/destination_filter_resource.go b/internal/provider/destination_filter_resource.go index 1d1a2de..e2f3864 100644 --- a/internal/provider/destination_filter_resource.go +++ b/internal/provider/destination_filter_resource.go @@ -166,6 +166,8 @@ func (r *destinationFilterResource) Create(ctx context.Context, req resource.Cre } destinationfilter := out.Data.Filter + resp.State.SetAttribute(ctx, path.Root("id"), destinationfilter.Id) + resp.State.SetAttribute(ctx, path.Root("destination_id"), destinationfilter.DestinationId) var state models.DestinationFilterState err = state.Fill(&destinationfilter) diff --git a/internal/provider/destination_resource.go b/internal/provider/destination_resource.go index 47ed98d..95d9ca0 100644 --- a/internal/provider/destination_resource.go +++ b/internal/provider/destination_resource.go @@ -549,6 +549,7 @@ func (r *destinationResource) Create(ctx context.Context, req resource.CreateReq return } + resp.State.SetAttribute(ctx, path.Root("id"), out.Data.Destination.Id) var state models.DestinationState err = state.Fill(&out.Data.Destination) diff --git a/internal/provider/destination_subscription_resource.go b/internal/provider/destination_subscription_resource.go index 4adcca4..c4f0a8a 100644 --- a/internal/provider/destination_subscription_resource.go +++ b/internal/provider/destination_subscription_resource.go @@ -132,6 +132,8 @@ func (r *destinationSubscriptionResource) Create(ctx context.Context, req resour destinationSubscription := out.Data.GetDestinationSubscription() + resp.State.SetAttribute(ctx, path.Root("id"), destinationSubscription.Id) + var state models.DestinationSubscriptionState err = state.Fill(destinationSubscription) if err != nil { diff --git a/internal/provider/function_resource.go b/internal/provider/function_resource.go index 4dd18bc..64f8f1a 100644 --- a/internal/provider/function_resource.go +++ b/internal/provider/function_resource.go @@ -156,6 +156,8 @@ func (r *functionResource) Create(ctx context.Context, req resource.CreateReques function := out.Data.GetFunction() + resp.State.SetAttribute(ctx, path.Root("id"), function.Id) + var state models.FunctionState state.Fill(api.Function(function)) diff --git a/internal/provider/insert_function_instance_resource.go b/internal/provider/insert_function_instance_resource.go index 618c2a4..d56384d 100644 --- a/internal/provider/insert_function_instance_resource.go +++ b/internal/provider/insert_function_instance_resource.go @@ -117,6 +117,8 @@ func (r *insertFunctionInstanceResource) Create(ctx context.Context, req resourc insertFunctionInstance := out.Data.InsertFunctionInstance + resp.State.SetAttribute(ctx, path.Root("id"), insertFunctionInstance.Id) + var state models.InsertFunctionInstanceState err = state.Fill(insertFunctionInstance) if err != nil { diff --git a/internal/provider/profiles_warehouse_resource.go b/internal/provider/profiles_warehouse_resource.go index 2735130..0851299 100644 --- a/internal/provider/profiles_warehouse_resource.go +++ b/internal/provider/profiles_warehouse_resource.go @@ -130,6 +130,9 @@ func (r *profilesWarehouseResource) Create(ctx context.Context, req resource.Cre profilesWarehouse := out.Data.GetProfilesWarehouse() + resp.State.SetAttribute(ctx, path.Root("id"), profilesWarehouse.Id) + resp.State.SetAttribute(ctx, path.Root("space_id"), plan.SpaceID.ValueString()) + var state models.ProfilesWarehouseState err = state.Fill(profilesWarehouse) if err != nil { diff --git a/internal/provider/reverse_etl_model_resource.go b/internal/provider/reverse_etl_model_resource.go index 99039fe..8b3bf7e 100644 --- a/internal/provider/reverse_etl_model_resource.go +++ b/internal/provider/reverse_etl_model_resource.go @@ -127,6 +127,8 @@ func (r *reverseETLModelResource) Create(ctx context.Context, req resource.Creat reverseETLModel := out.Data.ReverseEtlModel + resp.State.SetAttribute(ctx, path.Root("id"), reverseETLModel.Id) + var state models.ReverseETLModelState err = state.Fill(reverseETLModel) if err != nil { diff --git a/internal/provider/tracking_plan_resource.go b/internal/provider/tracking_plan_resource.go index 95e1e0a..9c7c43d 100644 --- a/internal/provider/tracking_plan_resource.go +++ b/internal/provider/tracking_plan_resource.go @@ -148,6 +148,8 @@ func (r *trackingPlanResource) Create(ctx context.Context, req resource.CreateRe trackingPlan := out.Data.GetTrackingPlan() + resp.State.SetAttribute(ctx, path.Root("id"), trackingPlan.Id) + var rules []models.RulesState plan.Rules.ElementsAs(ctx, &rules, false) diff --git a/internal/provider/transformation_resource.go b/internal/provider/transformation_resource.go index 94a3e3f..735b73c 100644 --- a/internal/provider/transformation_resource.go +++ b/internal/provider/transformation_resource.go @@ -178,6 +178,8 @@ func (r *transformationResource) Create(ctx context.Context, req resource.Create transformation := out.Data.GetTransformation() + resp.State.SetAttribute(ctx, path.Root("id"), transformation.Id) + var state models.TransformationState state.Fill(transformation) diff --git a/internal/provider/user_resource.go b/internal/provider/user_resource.go index 2011401..987ddb4 100644 --- a/internal/provider/user_resource.go +++ b/internal/provider/user_resource.go @@ -167,6 +167,9 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r return } + resp.State.SetAttribute(ctx, path.Root("id"), plan.Email.ValueString()) + resp.State.SetAttribute(ctx, path.Root("is_invite"), true) + user, err := findUser(r.authContext, r.client, plan.Email.ValueString()) if err != nil { resp.Diagnostics.AddError( diff --git a/internal/provider/warehouse_resource.go b/internal/provider/warehouse_resource.go index aac3e81..ed4191d 100644 --- a/internal/provider/warehouse_resource.go +++ b/internal/provider/warehouse_resource.go @@ -239,6 +239,8 @@ func (r *warehouseResource) Create(ctx context.Context, req resource.CreateReque warehouse := out.Data.GetWarehouse() + resp.State.SetAttribute(ctx, path.Root("id"), warehouse.Id) + var state models.WarehouseState err = state.Fill(warehouse) if err != nil {