Skip to content

Commit

Permalink
Merge pull request #29 from authsignal/AUT-2375
Browse files Browse the repository at this point in the history
AUT-2375: fixing recreation after manual delete behaviour
  • Loading branch information
LittleJono authored Oct 22, 2024
2 parents 5b3653e + 6c42c60 commit 640c9e8
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/action_configuration_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 12 additions & 6 deletions internal/provider/action_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/rule_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 12 additions & 6 deletions internal/provider/rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/theme_authsignal_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/theme_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/theme_model.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down
13 changes: 9 additions & 4 deletions internal/provider/theme_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/value_list_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions internal/provider/value_list_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 640c9e8

Please sign in to comment.