From 6c42c60e03f4646f41e02c97d5d608049f3c7316 Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Tue, 22 Oct 2024 14:49:47 +1300 Subject: [PATCH] AUT-2375: fixing recreation after manual delete behaviour --- go.mod | 2 +- go.sum | 2 ++ .../action_configuration_data_source.go | 4 ++-- .../provider/action_configuration_resource.go | 18 ++++++++++++------ internal/provider/provider.go | 2 +- internal/provider/rule_data_source.go | 4 ++-- internal/provider/rule_resource.go | 18 ++++++++++++------ internal/provider/theme_authsignal_objects.go | 2 +- internal/provider/theme_data_source.go | 4 ++-- internal/provider/theme_model.go | 2 +- internal/provider/theme_resource.go | 13 +++++++++---- internal/provider/value_list_data_source.go | 4 ++-- internal/provider/value_list_resource.go | 15 ++++++++++----- 13 files changed, 57 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 9a03ebf..9e6500a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/authsignal/terraform-provider-authsignal go 1.22.0 require ( - github.com/authsignal/authsignal-management-go/v2 v2.4.0 + github.com/authsignal/authsignal-management-go/v3 v3.0.0 github.com/hashicorp/terraform-plugin-docs v0.18.0 github.com/hashicorp/terraform-plugin-framework v1.7.0 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 diff --git a/go.sum b/go.sum index 94b074a..2ee80f4 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,8 @@ github.com/authsignal/authsignal-management-go/v2 v2.3.0 h1:blZvcBogpD1uRuANM86J github.com/authsignal/authsignal-management-go/v2 v2.3.0/go.mod h1:vRrL3bs794IPmy6BMbbmYCyf/QydU8Bg5cgZpCc4G9Q= github.com/authsignal/authsignal-management-go/v2 v2.4.0 h1:mcjI4zKBEW7RwnLpzZBvT1t4Zh2MjJrw8FcBmuGXok4= github.com/authsignal/authsignal-management-go/v2 v2.4.0/go.mod h1:vRrL3bs794IPmy6BMbbmYCyf/QydU8Bg5cgZpCc4G9Q= +github.com/authsignal/authsignal-management-go/v3 v3.0.0 h1:bvXQ+MCuhj+RXPH5FlZ08bAxHvcieFRdLyBA9OoiJY0= +github.com/authsignal/authsignal-management-go/v3 v3.0.0/go.mod h1:EnHz3/FOx7oIliprK2PpiUG4olWOH8y9vZr9DzoMDtY= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= diff --git a/internal/provider/action_configuration_data_source.go b/internal/provider/action_configuration_data_source.go index dae3e64..8b04d56 100644 --- a/internal/provider/action_configuration_data_source.go +++ b/internal/provider/action_configuration_data_source.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -90,7 +90,7 @@ func (d *actionConfigurationDataSource) Read(ctx context.Context, req datasource return } - actionConfiguration, err := d.client.GetActionConfiguration(data.ActionCode.ValueString()) + actionConfiguration, _, err := d.client.GetActionConfiguration(data.ActionCode.ValueString()) if err != nil { resp.Diagnostics.AddError( diff --git a/internal/provider/action_configuration_resource.go b/internal/provider/action_configuration_resource.go index 303223c..39799ce 100644 --- a/internal/provider/action_configuration_resource.go +++ b/internal/provider/action_configuration_resource.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -169,7 +169,7 @@ func (r *actionConfigurationResource) Create(ctx context.Context, req resource.C actionConfigurationToCreate.PromptToEnrollVerificationMethods = authsignal.SetValue(promptToEnrollVerificationMethodsSlice) } - actionConfiguration, err := r.client.CreateActionConfiguration(actionConfigurationToCreate) + actionConfiguration, _, err := r.client.CreateActionConfiguration(actionConfigurationToCreate) if err != nil { resp.Diagnostics.AddError( "Error creating action configuration", @@ -197,7 +197,13 @@ func (r *actionConfigurationResource) Read(ctx context.Context, req resource.Rea return } - actionConfiguration, err := r.client.GetActionConfiguration(state.ActionCode.ValueString()) + actionConfiguration, statusCode, err := r.client.GetActionConfiguration(state.ActionCode.ValueString()) + + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } + if err != nil { resp.Diagnostics.AddError( "Error Reading action configuration", @@ -319,7 +325,7 @@ func (r *actionConfigurationResource) Update(ctx context.Context, req resource.U actionConfigurationToUpdate.MessagingTemplates = authsignal.SetNull(messagingTemplatesJson) } - _, err2 := r.client.UpdateActionConfiguration(plan.ActionCode.ValueString(), actionConfigurationToUpdate) + _, _, err2 := r.client.UpdateActionConfiguration(plan.ActionCode.ValueString(), actionConfigurationToUpdate) if err2 != nil { resp.Diagnostics.AddError( "Error Updating Authsignal action configuration", @@ -328,7 +334,7 @@ func (r *actionConfigurationResource) Update(ctx context.Context, req resource.U return } - updatedActionConfiguration, err := r.client.GetActionConfiguration(plan.ActionCode.ValueString()) + updatedActionConfiguration, _, err := r.client.GetActionConfiguration(plan.ActionCode.ValueString()) if err != nil { resp.Diagnostics.AddError( "Error Reading Authsignal action configuration", @@ -357,7 +363,7 @@ func (r *actionConfigurationResource) Delete(ctx context.Context, req resource.D return } - _, err := r.client.DeleteActionConfiguration(state.ActionCode.ValueString()) + _, _, err := r.client.DeleteActionConfiguration(state.ActionCode.ValueString()) if err != nil { resp.Diagnostics.AddError( "Error Deleting Authsignal action configuration", diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 54c19ed..0a9d142 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -4,7 +4,7 @@ import ( "context" "os" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" diff --git a/internal/provider/rule_data_source.go b/internal/provider/rule_data_source.go index 5fab597..db9ffe2 100644 --- a/internal/provider/rule_data_source.go +++ b/internal/provider/rule_data_source.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -110,7 +110,7 @@ func (d *ruleDataSource) Read(ctx context.Context, req datasource.ReadRequest, r return } - rule, err := d.client.GetRule(data.ActionCode.ValueString(), data.RuleId.ValueString()) + rule, _, err := d.client.GetRule(data.ActionCode.ValueString(), data.RuleId.ValueString()) if err != nil { resp.Diagnostics.AddError( diff --git a/internal/provider/rule_resource.go b/internal/provider/rule_resource.go index 7601a22..76195c4 100644 --- a/internal/provider/rule_resource.go +++ b/internal/provider/rule_resource.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -198,7 +198,7 @@ func (r *ruleResource) Create(ctx context.Context, req resource.CreateRequest, r ruleToCreate.Conditions = authsignal.SetValue(conditionsJson) } - rule, err := r.client.CreateRule(plan.ActionCode.ValueString(), ruleToCreate) + rule, _, err := r.client.CreateRule(plan.ActionCode.ValueString(), ruleToCreate) if err != nil { resp.Diagnostics.AddError( "Error creating rule", @@ -225,7 +225,13 @@ func (r *ruleResource) Read(ctx context.Context, req resource.ReadRequest, resp return } - rule, err := r.client.GetRule(state.ActionCode.ValueString(), state.RuleId.ValueString()) + rule, statusCode, err := r.client.GetRule(state.ActionCode.ValueString(), state.RuleId.ValueString()) + + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } + if err != nil { resp.Diagnostics.AddError( "Error Reading rule", @@ -367,7 +373,7 @@ func (r *ruleResource) Update(ctx context.Context, req resource.UpdateRequest, r ruleToUpdate.Conditions = authsignal.SetNull(conditionsJson) } - _, err := r.client.UpdateRule(plan.ActionCode.ValueString(), plan.RuleId.ValueString(), ruleToUpdate) + _, _, err := r.client.UpdateRule(plan.ActionCode.ValueString(), plan.RuleId.ValueString(), ruleToUpdate) if err != nil { resp.Diagnostics.AddError( "Error Updating Authsignal rule", @@ -376,7 +382,7 @@ func (r *ruleResource) Update(ctx context.Context, req resource.UpdateRequest, r return } - updatedRule, err := r.client.GetRule(plan.ActionCode.ValueString(), plan.RuleId.ValueString()) + updatedRule, _, err := r.client.GetRule(plan.ActionCode.ValueString(), plan.RuleId.ValueString()) if err != nil { resp.Diagnostics.AddError( "Error Reading Authsignal rule", @@ -403,7 +409,7 @@ func (r *ruleResource) Delete(ctx context.Context, req resource.DeleteRequest, r return } - _, err := r.client.DeleteRule(state.ActionCode.ValueString(), state.RuleId.ValueString()) + _, _, err := r.client.DeleteRule(state.ActionCode.ValueString(), state.RuleId.ValueString()) if err != nil { resp.Diagnostics.AddError( "Error Deleting Authsignal rule", diff --git a/internal/provider/theme_authsignal_objects.go b/internal/provider/theme_authsignal_objects.go index b467cda..5ded966 100644 --- a/internal/provider/theme_authsignal_objects.go +++ b/internal/provider/theme_authsignal_objects.go @@ -3,7 +3,7 @@ package provider import ( "context" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" ) diff --git a/internal/provider/theme_data_source.go b/internal/provider/theme_data_source.go index 44089d2..87eeb5c 100644 --- a/internal/provider/theme_data_source.go +++ b/internal/provider/theme_data_source.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -370,7 +370,7 @@ func (d *themeDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, } func (d *themeDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - theme, err := d.client.GetTheme() + theme, _, err := d.client.GetTheme() if err != nil { resp.Diagnostics.AddError( diff --git a/internal/provider/theme_model.go b/internal/provider/theme_model.go index be479ea..2420683 100644 --- a/internal/provider/theme_model.go +++ b/internal/provider/theme_model.go @@ -1,7 +1,7 @@ package provider import ( - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" ) diff --git a/internal/provider/theme_resource.go b/internal/provider/theme_resource.go index 83adf25..08ad7cf 100644 --- a/internal/provider/theme_resource.go +++ b/internal/provider/theme_resource.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -412,7 +412,12 @@ func (r *themeResource) Create(ctx context.Context, req resource.CreateRequest, } func (r *themeResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - theme, err := r.client.GetTheme() + theme, statusCode, err := r.client.GetTheme() + + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } if err != nil { resp.Diagnostics.AddError( @@ -443,7 +448,7 @@ func (r *themeResource) Update(ctx context.Context, req resource.UpdateRequest, var themeToCreate = buildAuthsignalThemeUpdateObject(ctx, resp, plan) - theme, err := r.client.UpdateTheme(themeToCreate) + theme, _, err := r.client.UpdateTheme(themeToCreate) if err != nil { resp.Diagnostics.AddError( "Error creating theme", @@ -472,7 +477,7 @@ func (r *themeResource) Delete(ctx context.Context, req resource.DeleteRequest, var themeToCreate = buildAuthsignalThemeDeleteObject(state) - _, err := r.client.UpdateTheme(themeToCreate) + _, _, err := r.client.UpdateTheme(themeToCreate) if err != nil { resp.Diagnostics.AddError( "Error creating theme", diff --git a/internal/provider/value_list_data_source.go b/internal/provider/value_list_data_source.go index e275747..b1cfb59 100644 --- a/internal/provider/value_list_data_source.go +++ b/internal/provider/value_list_data_source.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -100,7 +100,7 @@ func (d *valueListDataSource) Read(ctx context.Context, req datasource.ReadReque return } - valueList, err := d.client.GetValueList(data.Alias.ValueString()) + valueList, _, err := d.client.GetValueList(data.Alias.ValueString()) if err != nil { resp.Diagnostics.AddError("Unable to Read Authsignal ValueList", err.Error()) return diff --git a/internal/provider/value_list_resource.go b/internal/provider/value_list_resource.go index fc83534..1525702 100644 --- a/internal/provider/value_list_resource.go +++ b/internal/provider/value_list_resource.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/authsignal/authsignal-management-go/v2" + "github.com/authsignal/authsignal-management-go/v3" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -180,7 +180,7 @@ func (r *valueListResource) Create(ctx context.Context, req resource.CreateReque valueListToCreate.ValueListItems = valueListItems - valueList, err := r.client.CreateValueList(valueListToCreate) + valueList, _, err := r.client.CreateValueList(valueListToCreate) if err != nil { resp.Diagnostics.AddError( "Error creating value list", @@ -208,7 +208,12 @@ func (r *valueListResource) Read(ctx context.Context, req resource.ReadRequest, return } - valueList, err := r.client.GetValueList(state.Alias.ValueString()) + valueList, statusCode, err := r.client.GetValueList(state.Alias.ValueString()) + + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } if err != nil { resp.Diagnostics.AddError( @@ -269,7 +274,7 @@ func (r *valueListResource) Update(ctx context.Context, req resource.UpdateReque valueListToUpdate.ValueListItems = valueListItems - valueList, err := r.client.UpdateValueList(plan.Alias.ValueString(), valueListToUpdate) + valueList, _, err := r.client.UpdateValueList(plan.Alias.ValueString(), valueListToUpdate) if err != nil { resp.Diagnostics.AddError( "Error updating value list", @@ -297,7 +302,7 @@ func (r *valueListResource) Delete(ctx context.Context, req resource.DeleteReque return } - _, err := r.client.DeleteValueList(state.Alias.ValueString()) + _, _, err := r.client.DeleteValueList(state.Alias.ValueString()) if err != nil { resp.Diagnostics.AddError( "Error Deleting Authsignal value list",