diff --git a/.changelog/40291.txt b/.changelog/40291.txt new file mode 100644 index 00000000000..97e2b1ae6b5 --- /dev/null +++ b/.changelog/40291.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_chatbot_teams_channel_configuration: Fix inconsistent provider result when order of `sns_topic_arns`changes +``` \ No newline at end of file diff --git a/internal/service/chatbot/slack_channel_configuration.go b/internal/service/chatbot/slack_channel_configuration.go index 472ea430539..a878965774f 100644 --- a/internal/service/chatbot/slack_channel_configuration.go +++ b/internal/service/chatbot/slack_channel_configuration.go @@ -202,6 +202,8 @@ func (r *slackChannelConfigurationResource) Read(ctx context.Context, request re return } + setTagsOut(ctx, output.Tags) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } diff --git a/internal/service/chatbot/teams_channel_configuration.go b/internal/service/chatbot/teams_channel_configuration.go index ddfb41cfc64..c472864a124 100644 --- a/internal/service/chatbot/teams_channel_configuration.go +++ b/internal/service/chatbot/teams_channel_configuration.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" @@ -73,9 +74,9 @@ func (r *teamsChannelConfigurationResource) Schema(ctx context.Context, request Required: true, }, "guardrail_policy_arns": schema.ListAttribute{ - Optional: true, - Computed: true, - ElementType: types.StringType, + CustomType: fwtypes.ListOfStringType, + Optional: true, + Computed: true, PlanModifiers: []planmodifier.List{ listplanmodifier.UseStateForUnknown(), }, @@ -92,12 +93,12 @@ func (r *teamsChannelConfigurationResource) Schema(ctx context.Context, request stringplanmodifier.UseStateForUnknown(), }, }, - "sns_topic_arns": schema.ListAttribute{ - Optional: true, - Computed: true, - ElementType: types.StringType, - PlanModifiers: []planmodifier.List{ - listplanmodifier.UseStateForUnknown(), + "sns_topic_arns": schema.SetAttribute{ + CustomType: fwtypes.SetOfStringType, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), }, }, names.AttrTags: tftags.TagsAttribute(), @@ -204,6 +205,8 @@ func (r *teamsChannelConfigurationResource) Read(ctx context.Context, request re return } + setTagsOut(ctx, output.Tags) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -221,7 +224,13 @@ func (r *teamsChannelConfigurationResource) Update(ctx context.Context, request conn := r.Meta().ChatbotClient(ctx) - if teamsChannelConfigurationHasChanges(ctx, new, old) { + diff, d := fwflex.Calculate(ctx, new, old) + response.Diagnostics.Append(d...) + if response.Diagnostics.HasError() { + return + } + + if diff.HasChanges() { input := &chatbot.UpdateMicrosoftTeamsChannelConfigurationInput{} response.Diagnostics.Append(fwflex.Expand(ctx, new, input)...) if response.Diagnostics.HasError() { @@ -402,34 +411,19 @@ func waitTeamsChannelConfigurationDeleted(ctx context.Context, conn *chatbot.Cli } type teamsChannelConfigurationResourceModel struct { - ChannelID types.String `tfsdk:"channel_id"` - ChannelName types.String `tfsdk:"channel_name"` - ChatConfigurationARN types.String `tfsdk:"chat_configuration_arn"` - ConfigurationName types.String `tfsdk:"configuration_name"` - GuardrailPolicyARNs types.List `tfsdk:"guardrail_policy_arns"` - IAMRoleARN types.String `tfsdk:"iam_role_arn"` - LoggingLevel fwtypes.StringEnum[loggingLevel] `tfsdk:"logging_level"` - SNSTopicARNs types.List `tfsdk:"sns_topic_arns"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` - TeamID types.String `tfsdk:"team_id"` - TeamName types.String `tfsdk:"team_name"` - TenantID types.String `tfsdk:"tenant_id"` - Timeouts timeouts.Value `tfsdk:"timeouts"` - UserAuthorizationRequired types.Bool `tfsdk:"user_authorization_required"` -} - -func teamsChannelConfigurationHasChanges(_ context.Context, plan, state teamsChannelConfigurationResourceModel) bool { - return !plan.ChannelID.Equal(state.ChannelID) || - !plan.ChannelName.Equal(state.ChannelName) || - !plan.ChatConfigurationARN.Equal(state.ChatConfigurationARN) || - !plan.ConfigurationName.Equal(state.ConfigurationName) || - !plan.GuardrailPolicyARNs.Equal(state.GuardrailPolicyARNs) || - !plan.IAMRoleARN.Equal(state.IAMRoleARN) || - !plan.LoggingLevel.Equal(state.LoggingLevel) || - !plan.SNSTopicARNs.Equal(state.SNSTopicARNs) || - !plan.TeamID.Equal(state.TeamID) || - !plan.TeamName.Equal(state.TeamName) || - !plan.TenantID.Equal(state.TenantID) || - !plan.UserAuthorizationRequired.Equal(state.UserAuthorizationRequired) + ChannelID types.String `tfsdk:"channel_id"` + ChannelName types.String `tfsdk:"channel_name"` + ChatConfigurationARN types.String `tfsdk:"chat_configuration_arn"` + ConfigurationName types.String `tfsdk:"configuration_name"` + GuardrailPolicyARNs fwtypes.ListValueOf[types.String] `tfsdk:"guardrail_policy_arns"` + IAMRoleARN types.String `tfsdk:"iam_role_arn"` + LoggingLevel fwtypes.StringEnum[loggingLevel] `tfsdk:"logging_level"` + SNSTopicARNs fwtypes.SetValueOf[types.String] `tfsdk:"sns_topic_arns"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + TeamID types.String `tfsdk:"team_id"` + TeamName types.String `tfsdk:"team_name"` + TenantID types.String `tfsdk:"tenant_id"` + Timeouts timeouts.Value `tfsdk:"timeouts"` + UserAuthorizationRequired types.Bool `tfsdk:"user_authorization_required"` }