Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/chatbot_teams_channel_configuration: Fix SNS topic ARNs ordering #40291

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/40291.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_chatbot_teams_channel_configuration: Fix inconsistent provider result when order of `sns_topic_arns`changes
```
2 changes: 2 additions & 0 deletions internal/service/chatbot/slack_channel_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
}

Expand Down
74 changes: 34 additions & 40 deletions internal/service/chatbot/teams_channel_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
},
Expand All @@ -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(),
Expand Down Expand Up @@ -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)...)
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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"`
}
Loading