From c6bb62fc8c73ef3cf90cfbe83aeba2ec6fe1bba1 Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Thu, 16 May 2024 17:27:15 +1200 Subject: [PATCH 1/6] AUT-2030: adding support for contextual messaging in action configurations --- examples/provider/provider.tf | 8 ++- .../action_configuration_data_source.go | 16 +++++ .../provider/action_configuration_resource.go | 64 ++++++++++++++++--- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index f0b786c..9af6a41 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,7 +1,9 @@ # Configuration-based authentication provider "authsignal" { // For production systems please configure these as environment variables in your CI/CD process. - host = "https://authsignal.com/not-a-real-endpoint" - tenant_id = "123" - api_secret = "helloworld" + host = "https://api.authsignal.com/v1/management" // AUTHSIGNAL_HOST + tenant_id = "123" // AUTHSIGNAL_TENANT_ID + api_secret = "helloworld" // AUTHSIGNAL_API_SECRET } + +# These values can be found under the `Settings -> API keys` section of Authsignal's admin portal. diff --git a/internal/provider/action_configuration_data_source.go b/internal/provider/action_configuration_data_source.go index 96c2e5b..2ed6bcd 100644 --- a/internal/provider/action_configuration_data_source.go +++ b/internal/provider/action_configuration_data_source.go @@ -2,6 +2,7 @@ package provider import ( "context" + "encoding/json" "fmt" "github.com/authsignal/authsignal-management-go/v2" @@ -29,6 +30,7 @@ type actionConfigurationDataSourceModel struct { TenantId types.String `tfsdk:"tenant_id"` DefaultUserActionResult types.String `tfsdk:"default_user_action_result"` LastActionCreatedAt types.String `tfsdk:"last_action_created_at"` + MessagingTemplates types.String `tfsdk:"messaging_templates"` } func (d *actionConfigurationDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -54,6 +56,10 @@ func (d *actionConfigurationDataSource) Schema(_ context.Context, _ datasource.S Description: "The ID of your tenant. This can be found in the admin portal.", Computed: true, }, + "messaging_templates": schema.StringAttribute{ + Description: "Optional messaging templates to be shown in Authsignal's pre-built UI.", + Optional: true, + }, }, } } @@ -77,11 +83,21 @@ func (d *actionConfigurationDataSource) Read(ctx context.Context, req datasource return } + messagingTemplatesJson, err := json.Marshal(actionConfiguration.MessagingTemplates) + if err != nil { + resp.Diagnostics.AddError( + "Unable to marshall messaging templates", + err.Error(), + ) + return + } + actionConfigurationState := actionConfigurationDataSourceModel{ ActionCode: types.StringValue(actionConfiguration.ActionCode), TenantId: types.StringValue(actionConfiguration.TenantId), DefaultUserActionResult: types.StringValue(actionConfiguration.DefaultUserActionResult), LastActionCreatedAt: types.StringValue(actionConfiguration.LastActionCreatedAt), + MessagingTemplates: types.StringValue(string(messagingTemplatesJson)), } diags2 := resp.State.Set(ctx, &actionConfigurationState) diff --git a/internal/provider/action_configuration_resource.go b/internal/provider/action_configuration_resource.go index b26d5b0..b77781b 100644 --- a/internal/provider/action_configuration_resource.go +++ b/internal/provider/action_configuration_resource.go @@ -2,6 +2,7 @@ package provider import ( "context" + "encoding/json" "fmt" "github.com/authsignal/authsignal-management-go/v2" @@ -35,6 +36,7 @@ type actionConfigurationResourceModel struct { LastActionCreatedAt types.String `tfsdk:"last_action_created_at"` TenantId types.String `tfsdk:"tenant_id"` DefaultUserActionResult types.String `tfsdk:"default_user_action_result"` + MessagingTemplates types.String `tfsdk:"messaging_templates"` } func (r *actionConfigurationResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -69,6 +71,10 @@ func (r *actionConfigurationResource) Schema(_ context.Context, _ resource.Schem stringplanmodifier.UseStateForUnknown(), }, }, + "messaging_templates": schema.StringAttribute{ + Description: "Optional messaging templates to be shown in Authsignal's pre-built UI.", + Optional: true, + }, }, } } @@ -81,6 +87,17 @@ func (r *actionConfigurationResource) Create(ctx context.Context, req resource.C return } + var messagingTemplatesJson authsignal.MessagingTemplates + + err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) + if err != nil { + resp.Diagnostics.AddError( + "Unable to unmarshall messaging templates", + err.Error(), + ) + return + } + var actionConfigurationToCreate = authsignal.ActionConfiguration{} var actionConfigurationActionCode = plan.ActionCode.ValueString() @@ -93,6 +110,10 @@ func (r *actionConfigurationResource) Create(ctx context.Context, req resource.C actionConfigurationToCreate.DefaultUserActionResult = authsignal.SetValue(actionConfigurationDefaultUserActionResult) } + if len(string(plan.MessagingTemplates.ValueString())) > 0 { + actionConfigurationToCreate.MessagingTemplates = authsignal.SetValue(messagingTemplatesJson) + } + actionConfiguration, err := r.client.CreateActionConfiguration(actionConfigurationToCreate) if err != nil { resp.Diagnostics.AddError( @@ -132,10 +153,23 @@ func (r *actionConfigurationResource) Read(ctx context.Context, req resource.Rea return } + messagingTemplatesJson, err := json.Marshal(actionConfiguration.MessagingTemplates) + if err != nil { + resp.Diagnostics.AddError( + "Unable to marshall messaging templates", + err.Error(), + ) + return + } + state.DefaultUserActionResult = types.StringValue(actionConfiguration.DefaultUserActionResult) state.LastActionCreatedAt = types.StringValue(actionConfiguration.LastActionCreatedAt) state.TenantId = types.StringValue(actionConfiguration.TenantId) + if len(string(messagingTemplatesJson)) > 0 { + state.MessagingTemplates = types.StringValue(string(messagingTemplatesJson)) + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -151,14 +185,9 @@ func (r *actionConfigurationResource) Update(ctx context.Context, req resource.U return } - var actionConfigurationToUpdate = authsignal.ActionConfiguration{} + var messagingTemplatesJson authsignal.MessagingTemplates - var actionConfigurationActionCode = plan.ActionCode.ValueString() - if len(actionConfigurationActionCode) > 0 { - actionConfigurationToUpdate.ActionCode = authsignal.SetValue(actionConfigurationActionCode) - } else { - actionConfigurationToUpdate.ActionCode = authsignal.SetNull(actionConfigurationActionCode) - } + var actionConfigurationToUpdate = authsignal.ActionConfiguration{} var actionConfigurationDefaultUserActionResult = plan.DefaultUserActionResult.ValueString() if len(actionConfigurationDefaultUserActionResult) > 0 { @@ -167,11 +196,26 @@ func (r *actionConfigurationResource) Update(ctx context.Context, req resource.U actionConfigurationToUpdate.DefaultUserActionResult = authsignal.SetNull(actionConfigurationDefaultUserActionResult) } - _, err := r.client.UpdateActionConfiguration(plan.ActionCode.ValueString(), actionConfigurationToUpdate) - if err != nil { + if len(string(plan.MessagingTemplates.ValueString())) > 0 { + err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) + if err != nil { + resp.Diagnostics.AddError( + "Unable to unmarshall messaging templates", + err.Error(), + ) + return + } + + actionConfigurationToUpdate.MessagingTemplates = authsignal.SetValue(messagingTemplatesJson) + } else { + actionConfigurationToUpdate.MessagingTemplates = authsignal.SetNull(messagingTemplatesJson) + } + + _, err2 := r.client.UpdateActionConfiguration(plan.ActionCode.ValueString(), actionConfigurationToUpdate) + if err2 != nil { resp.Diagnostics.AddError( "Error Updating Authsignal action configuration", - "Could not update action configuration, unexpected error: "+err.Error(), + "Could not update action configuration, unexpected error: "+err2.Error(), ) return } From 40e41776debb0255b2df64226e65f73ae2afde49 Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Thu, 16 May 2024 17:29:27 +1200 Subject: [PATCH 2/6] AUT-2030: updating docs --- docs/data-sources/action_configuration.md | 4 ++++ docs/index.md | 8 +++++--- docs/resources/action_configuration.md | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/data-sources/action_configuration.md b/docs/data-sources/action_configuration.md index 667cd7d..4436ee8 100644 --- a/docs/data-sources/action_configuration.md +++ b/docs/data-sources/action_configuration.md @@ -26,6 +26,10 @@ data "authsignal_action_configuration" "test" { - `action_code` (String) The name of the action that users perform which you will track. (e.g 'login') +### Optional + +- `messaging_templates` (String) Optional messaging templates to be shown in Authsignal's pre-built UI. + ### Read-Only - `default_user_action_result` (String) The default action behavior if no rules match. (i.e 'CHALLENGE') diff --git a/docs/index.md b/docs/index.md index c2cb3ba..fb021b7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,10 +16,12 @@ description: |- # Configuration-based authentication provider "authsignal" { // For production systems please configure these as environment variables in your CI/CD process. - host = "https://authsignal.com/not-a-real-endpoint" - tenant_id = "123" - api_secret = "helloworld" + host = "https://api.authsignal.com/v1/management" // AUTHSIGNAL_HOST + tenant_id = "123" // AUTHSIGNAL_TENANT_ID + api_secret = "helloworld" // AUTHSIGNAL_API_SECRET } + +# These values can be found under the `Settings -> API keys` section of Authsignal's admin portal. ``` diff --git a/docs/resources/action_configuration.md b/docs/resources/action_configuration.md index 3fea94b..f4e1ebf 100644 --- a/docs/resources/action_configuration.md +++ b/docs/resources/action_configuration.md @@ -28,6 +28,10 @@ resource "authsignal_action_configuration" "terraform-provider-test" { - `action_code` (String) The name of the action that users perform which you will track. (e.g 'login') - `default_user_action_result` (String) The default action behavior if no rules match. (i.e 'CHALLENGE') +### Optional + +- `messaging_templates` (String) Optional messaging templates to be shown in Authsignal's pre-built UI. + ### Read-Only - `last_action_created_at` (String) The date of when an action was last tracked for any user. From aa297a7034d0adb229a0cc6440fbc5dd29fd7d2b Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Mon, 20 May 2024 17:27:14 +1200 Subject: [PATCH 3/6] AUT-2030: fixing handling of empty messaging templates --- docs/index.md | 8 ++-- examples/provider/provider.tf | 8 ++-- .../provider/action_configuration_resource.go | 22 ++++++----- .../action_configuration_resource_test.go | 38 +++++++++++++++++++ internal/provider/rule_resource.go | 12 ++++-- 5 files changed, 66 insertions(+), 22 deletions(-) diff --git a/docs/index.md b/docs/index.md index fb021b7..48eccc0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,10 +15,10 @@ description: |- ```terraform # Configuration-based authentication provider "authsignal" { - // For production systems please configure these as environment variables in your CI/CD process. - host = "https://api.authsignal.com/v1/management" // AUTHSIGNAL_HOST - tenant_id = "123" // AUTHSIGNAL_TENANT_ID - api_secret = "helloworld" // AUTHSIGNAL_API_SECRET + # For production systems please configure these as environment variables in your CI/CD process. + host = "https://api.authsignal.com/v1/management" # AUTHSIGNAL_HOST + tenant_id = "123" # AUTHSIGNAL_TENANT_ID + api_secret = "helloworld" # AUTHSIGNAL_API_SECRET } # These values can be found under the `Settings -> API keys` section of Authsignal's admin portal. diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 9af6a41..7ed56c6 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,9 +1,9 @@ # Configuration-based authentication provider "authsignal" { - // For production systems please configure these as environment variables in your CI/CD process. - host = "https://api.authsignal.com/v1/management" // AUTHSIGNAL_HOST - tenant_id = "123" // AUTHSIGNAL_TENANT_ID - api_secret = "helloworld" // AUTHSIGNAL_API_SECRET + # For production systems please configure these as environment variables in your CI/CD process. + host = "https://api.authsignal.com/v1/management" # AUTHSIGNAL_HOST + tenant_id = "123" # AUTHSIGNAL_TENANT_ID + api_secret = "helloworld" # AUTHSIGNAL_API_SECRET } # These values can be found under the `Settings -> API keys` section of Authsignal's admin portal. diff --git a/internal/provider/action_configuration_resource.go b/internal/provider/action_configuration_resource.go index b77781b..3f9b8bc 100644 --- a/internal/provider/action_configuration_resource.go +++ b/internal/provider/action_configuration_resource.go @@ -89,13 +89,15 @@ func (r *actionConfigurationResource) Create(ctx context.Context, req resource.C var messagingTemplatesJson authsignal.MessagingTemplates - err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) - if err != nil { - resp.Diagnostics.AddError( - "Unable to unmarshall messaging templates", - err.Error(), - ) - return + if len(string(plan.MessagingTemplates.ValueString())) > 0 { + err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) + if err != nil { + resp.Diagnostics.AddError( + "Unable to unmarshal messaging templates 1", + err.Error(), + ) + return + } } var actionConfigurationToCreate = authsignal.ActionConfiguration{} @@ -156,7 +158,7 @@ func (r *actionConfigurationResource) Read(ctx context.Context, req resource.Rea messagingTemplatesJson, err := json.Marshal(actionConfiguration.MessagingTemplates) if err != nil { resp.Diagnostics.AddError( - "Unable to marshall messaging templates", + "Unable to marshal messaging templates", err.Error(), ) return @@ -166,7 +168,7 @@ func (r *actionConfigurationResource) Read(ctx context.Context, req resource.Rea state.LastActionCreatedAt = types.StringValue(actionConfiguration.LastActionCreatedAt) state.TenantId = types.StringValue(actionConfiguration.TenantId) - if len(string(messagingTemplatesJson)) > 0 { + if actionConfiguration.MessagingTemplates != nil { state.MessagingTemplates = types.StringValue(string(messagingTemplatesJson)) } @@ -200,7 +202,7 @@ func (r *actionConfigurationResource) Update(ctx context.Context, req resource.U err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) if err != nil { resp.Diagnostics.AddError( - "Unable to unmarshall messaging templates", + "Unable to unmarshal messaging templates 2", err.Error(), ) return diff --git a/internal/provider/action_configuration_resource_test.go b/internal/provider/action_configuration_resource_test.go index 4dc1728..ffa19e3 100644 --- a/internal/provider/action_configuration_resource_test.go +++ b/internal/provider/action_configuration_resource_test.go @@ -24,6 +24,25 @@ func TestAccActionConfigurationResource(t *testing.T) { resource.TestCheckResourceAttr("authsignal_action_configuration.test", "tenant_id", "ec3910e7-ab32-479e-b58b-36a122631d58"), ), }, + { + Config: ` + resource "authsignal_action_configuration" "test-templates" { + action_code = "terraform-acceptance-test-templates" + default_user_action_result = "ALLOW" + messaging_templates = jsonencode({ + "en": { + "defaultTemplate": "hello world" + } + }) + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "action_code", "terraform-acceptance-test-templates"), + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "default_user_action_result", "ALLOW"), + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "tenant_id", "ec3910e7-ab32-479e-b58b-36a122631d58"), + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "messaging_templates", "{\"en\":{\"defaultTemplate\":\"hello world\"}}"), + ), + }, // Update and Read testing { Config: ` @@ -38,6 +57,25 @@ func TestAccActionConfigurationResource(t *testing.T) { resource.TestCheckResourceAttr("authsignal_action_configuration.test", "tenant_id", "ec3910e7-ab32-479e-b58b-36a122631d58"), ), }, + { + Config: ` + resource "authsignal_action_configuration" "test-templates" { + action_code = "terraform-acceptance-test-templates" + default_user_action_result = "ALLOW" + messaging_templates = jsonencode({ + "fr": { + "defaultTemplate": "bonjour" + } + }) + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "action_code", "terraform-acceptance-test-templates"), + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "default_user_action_result", "ALLOW"), + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "tenant_id", "ec3910e7-ab32-479e-b58b-36a122631d58"), + resource.TestCheckResourceAttr("authsignal_action_configuration.test-templates", "messaging_templates", "{\"fr\":{\"defaultTemplate\":\"bonjour\"}}"), + ), + }, // Delete testing automatically occurs in TestCase }, }) diff --git a/internal/provider/rule_resource.go b/internal/provider/rule_resource.go index 1340b19..350c7c4 100644 --- a/internal/provider/rule_resource.go +++ b/internal/provider/rule_resource.go @@ -161,7 +161,7 @@ func (r *ruleResource) Create(ctx context.Context, req resource.CreateRequest, r err := json.Unmarshal([]byte(plan.Conditions.ValueString()), &conditionsJson) if err != nil { resp.Diagnostics.AddError( - "Unable to marshall conditions", + "Unable to marshal conditions", err.Error(), ) return @@ -252,7 +252,7 @@ func (r *ruleResource) Read(ctx context.Context, req resource.ReadRequest, resp conditionsJson, err := json.Marshal(rule.Conditions) if err != nil { resp.Diagnostics.AddError( - "Unable to marshall conditions", + "Unable to marshal conditions", err.Error(), ) return @@ -264,7 +264,7 @@ func (r *ruleResource) Read(ctx context.Context, req resource.ReadRequest, resp state.Type = types.StringValue(rule.Type) state.VerificationMethods = verificationMethodsList state.PromptToEnrollVerificationMethods = promptToEnrollVerificationMethodsList - state.Conditions = types.StringValue(string(conditionsJson)) + state.TenantId = types.StringValue(rule.TenantId) if len(rule.Description) > 0 { @@ -275,6 +275,10 @@ func (r *ruleResource) Read(ctx context.Context, req resource.ReadRequest, resp state.DefaultVerificationMethod = types.StringValue(rule.DefaultVerificationMethod) } + if rule.Conditions != nil { + state.Conditions = types.StringValue(string(conditionsJson)) + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -309,7 +313,7 @@ func (r *ruleResource) Update(ctx context.Context, req resource.UpdateRequest, r err2 := json.Unmarshal([]byte(plan.Conditions.ValueString()), &conditionsJson) if err2 != nil { resp.Diagnostics.AddError( - "Unable to marshall conditions", + "Unable to marshal conditions", err2.Error(), ) return From d46c34e6f5d3b5641c7553aebbec18e1dd27658a Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Mon, 20 May 2024 17:32:46 +1200 Subject: [PATCH 4/6] AUT-2030: fixing action config data sources --- internal/provider/action_configuration_data_source.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/provider/action_configuration_data_source.go b/internal/provider/action_configuration_data_source.go index 2ed6bcd..922a7b0 100644 --- a/internal/provider/action_configuration_data_source.go +++ b/internal/provider/action_configuration_data_source.go @@ -97,7 +97,10 @@ func (d *actionConfigurationDataSource) Read(ctx context.Context, req datasource TenantId: types.StringValue(actionConfiguration.TenantId), DefaultUserActionResult: types.StringValue(actionConfiguration.DefaultUserActionResult), LastActionCreatedAt: types.StringValue(actionConfiguration.LastActionCreatedAt), - MessagingTemplates: types.StringValue(string(messagingTemplatesJson)), + } + + if actionConfiguration.MessagingTemplates != nil { + actionConfigurationState.MessagingTemplates = types.StringValue(string(messagingTemplatesJson)) } diags2 := resp.State.Set(ctx, &actionConfigurationState) From 38e69b42fb64af2f507355297aaf6bfa27f771b4 Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Tue, 21 May 2024 10:42:24 +1200 Subject: [PATCH 5/6] AUT-2030: fixing log messages --- internal/provider/action_configuration_data_source.go | 2 +- internal/provider/action_configuration_resource.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/provider/action_configuration_data_source.go b/internal/provider/action_configuration_data_source.go index 922a7b0..973a3ce 100644 --- a/internal/provider/action_configuration_data_source.go +++ b/internal/provider/action_configuration_data_source.go @@ -86,7 +86,7 @@ func (d *actionConfigurationDataSource) Read(ctx context.Context, req datasource messagingTemplatesJson, err := json.Marshal(actionConfiguration.MessagingTemplates) if err != nil { resp.Diagnostics.AddError( - "Unable to marshall messaging templates", + "Unable to marshal messaging templates", err.Error(), ) return diff --git a/internal/provider/action_configuration_resource.go b/internal/provider/action_configuration_resource.go index 3f9b8bc..ec610f9 100644 --- a/internal/provider/action_configuration_resource.go +++ b/internal/provider/action_configuration_resource.go @@ -93,7 +93,7 @@ func (r *actionConfigurationResource) Create(ctx context.Context, req resource.C err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) if err != nil { resp.Diagnostics.AddError( - "Unable to unmarshal messaging templates 1", + "Unable to unmarshal messaging templates", err.Error(), ) return @@ -202,7 +202,7 @@ func (r *actionConfigurationResource) Update(ctx context.Context, req resource.U err := json.Unmarshal([]byte(plan.MessagingTemplates.ValueString()), &messagingTemplatesJson) if err != nil { resp.Diagnostics.AddError( - "Unable to unmarshal messaging templates 2", + "Unable to unmarshal messaging templates", err.Error(), ) return From 7185828c2fb2dc1ce417dd1f5ffd4941812945aa Mon Sep 17 00:00:00 2001 From: Jono Templeton Date: Tue, 21 May 2024 15:30:27 +1200 Subject: [PATCH 6/6] AUT-2030: various fixes --- docs/data-sources/action_configuration.md | 5 +---- go.mod | 2 +- go.sum | 4 ++-- internal/provider/action_configuration_data_source.go | 2 +- internal/provider/action_configuration_resource.go | 2 ++ internal/provider/rule_resource.go | 6 ++++++ 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/data-sources/action_configuration.md b/docs/data-sources/action_configuration.md index 4436ee8..e0ebc1c 100644 --- a/docs/data-sources/action_configuration.md +++ b/docs/data-sources/action_configuration.md @@ -26,12 +26,9 @@ data "authsignal_action_configuration" "test" { - `action_code` (String) The name of the action that users perform which you will track. (e.g 'login') -### Optional - -- `messaging_templates` (String) Optional messaging templates to be shown in Authsignal's pre-built UI. - ### Read-Only - `default_user_action_result` (String) The default action behavior if no rules match. (i.e 'CHALLENGE') - `last_action_created_at` (String) The date of when an action was last tracked for any user. +- `messaging_templates` (String) Optional messaging templates to be shown in Authsignal's pre-built UI. - `tenant_id` (String) The ID of your tenant. This can be found in the admin portal. diff --git a/go.mod b/go.mod index e3cae96..90a66c0 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.0.1 + github.com/authsignal/authsignal-management-go/v2 v2.1.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 035d987..869fb49 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/authsignal/authsignal-management-go/v2 v2.0.1 h1:KQL4UNCaPNQUPf3zKQOiyJazBFInop5NNhgr7shKazs= -github.com/authsignal/authsignal-management-go/v2 v2.0.1/go.mod h1:vRrL3bs794IPmy6BMbbmYCyf/QydU8Bg5cgZpCc4G9Q= +github.com/authsignal/authsignal-management-go/v2 v2.1.0 h1:dg2RaLru412uE2O+18WPGq5io44BC7pgkYCi2qC4+pE= +github.com/authsignal/authsignal-management-go/v2 v2.1.0/go.mod h1:vRrL3bs794IPmy6BMbbmYCyf/QydU8Bg5cgZpCc4G9Q= 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 973a3ce..01e4e02 100644 --- a/internal/provider/action_configuration_data_source.go +++ b/internal/provider/action_configuration_data_source.go @@ -58,7 +58,7 @@ func (d *actionConfigurationDataSource) Schema(_ context.Context, _ datasource.S }, "messaging_templates": schema.StringAttribute{ Description: "Optional messaging templates to be shown in Authsignal's pre-built UI.", - Optional: true, + Computed: true, }, }, } diff --git a/internal/provider/action_configuration_resource.go b/internal/provider/action_configuration_resource.go index ec610f9..824cb6f 100644 --- a/internal/provider/action_configuration_resource.go +++ b/internal/provider/action_configuration_resource.go @@ -170,6 +170,8 @@ func (r *actionConfigurationResource) Read(ctx context.Context, req resource.Rea if actionConfiguration.MessagingTemplates != nil { state.MessagingTemplates = types.StringValue(string(messagingTemplatesJson)) + } else { + state.MessagingTemplates = types.StringNull() } diags = resp.State.Set(ctx, &state) diff --git a/internal/provider/rule_resource.go b/internal/provider/rule_resource.go index 350c7c4..b39aefc 100644 --- a/internal/provider/rule_resource.go +++ b/internal/provider/rule_resource.go @@ -269,14 +269,20 @@ func (r *ruleResource) Read(ctx context.Context, req resource.ReadRequest, resp if len(rule.Description) > 0 { state.Description = types.StringValue(rule.Description) + } else { + state.Description = types.StringNull() } if len(rule.DefaultVerificationMethod) > 0 { state.DefaultVerificationMethod = types.StringValue(rule.DefaultVerificationMethod) + } else { + state.DefaultVerificationMethod = types.StringNull() } if rule.Conditions != nil { state.Conditions = types.StringValue(string(conditionsJson)) + } else { + state.Conditions = types.StringNull() } diags = resp.State.Set(ctx, &state)