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: Fix SNS topic ARNs ordering in Slack channel configuration #40253

Merged
merged 7 commits into from
Nov 22, 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/40253.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_chatbot_slack_channel_configuration: Fix inconsistent provider result when order of `sns_topic_arns`changes
```
69 changes: 31 additions & 38 deletions internal/service/chatbot/slack_channel_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 @@ -64,9 +65,9 @@ func (r *slackChannelConfigurationResource) 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 Down Expand Up @@ -95,12 +96,12 @@ func (r *slackChannelConfigurationResource) Schema(ctx context.Context, request
"slack_team_name": schema.StringAttribute{
Computed: true,
},
"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 @@ -218,7 +219,13 @@ func (r *slackChannelConfigurationResource) Update(ctx context.Context, request

conn := r.Meta().ChatbotClient(ctx)

if slackChannelConfigurationHasChanges(ctx, new, old) {
diff, d := fwflex.Calculate(ctx, new, old)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
}

if diff.HasChanges() {
input := &chatbot.UpdateSlackChannelConfigurationInput{}
response.Diagnostics.Append(fwflex.Expand(ctx, new, input)...)
if response.Diagnostics.HasError() {
Expand Down Expand Up @@ -398,20 +405,20 @@ func waitSlackChannelConfigurationDeleted(ctx context.Context, conn *chatbot.Cli
}

type slackChannelConfigurationResourceModel struct {
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"`
SlackChannelID types.String `tfsdk:"slack_channel_id"`
SlackChannelName types.String `tfsdk:"slack_channel_name"`
SlackTeamID types.String `tfsdk:"slack_team_id"`
SlackTeamName types.String `tfsdk:"slack_team_name"`
SNSTopicARNs types.List `tfsdk:"sns_topic_arns"`
Tags tftags.Map `tfsdk:"tags"`
TagsAll tftags.Map `tfsdk:"tags_all"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
UserAuthorizationRequired types.Bool `tfsdk:"user_authorization_required"`
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"`
SlackChannelID types.String `tfsdk:"slack_channel_id"`
SlackChannelName types.String `tfsdk:"slack_channel_name"`
SlackTeamID types.String `tfsdk:"slack_team_id"`
SlackTeamName types.String `tfsdk:"slack_team_name"`
SNSTopicARNs fwtypes.SetValueOf[types.String] `tfsdk:"sns_topic_arns"`
Tags tftags.Map `tfsdk:"tags"`
TagsAll tftags.Map `tfsdk:"tags_all"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
UserAuthorizationRequired types.Bool `tfsdk:"user_authorization_required"`
}

func (data *slackChannelConfigurationResourceModel) InitFromID() error {
Expand All @@ -434,17 +441,3 @@ func (loggingLevel) Values() []loggingLevel {
loggingLevelNone,
}
}

func slackChannelConfigurationHasChanges(_ context.Context, plan, state slackChannelConfigurationResourceModel) bool {
return !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.SlackChannelID.Equal(state.SlackChannelID) ||
!plan.SlackChannelName.Equal(state.SlackChannelName) ||
!plan.SlackTeamID.Equal(state.SlackTeamID) ||
!plan.SlackTeamName.Equal(state.SlackTeamName) ||
!plan.SNSTopicARNs.Equal(state.SNSTopicARNs) ||
!plan.UserAuthorizationRequired.Equal(state.UserAuthorizationRequired)
}
2 changes: 1 addition & 1 deletion internal/service/rds/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func TestAccRDSCluster_storageTypeGeneralPurposeToProvisionedIOPS(t *testing.T)
{
Config: testAccClusterConfig_storageChange(rName, "gp3"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "storage_type", "gp3"),
resource.TestCheckResourceAttr(resourceName, names.AttrStorageType, "gp3"),
),
},
{
Expand Down
2 changes: 1 addition & 1 deletion internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2589,7 +2589,7 @@ func dbInstancePopulateModify(input *rds.ModifyDBInstanceInput, d *schema.Resour

if slices.Contains([]string{storageTypeIO1, storageTypeIO2}, aws.ToString(input.StorageType)) {
input.Iops = aws.Int32(int32(d.Get(names.AttrIOPS).(int)))
input.AllocatedStorage = aws.Int32(int32(d.Get("allocated_storage").(int)))
input.AllocatedStorage = aws.Int32(int32(d.Get(names.AttrAllocatedStorage).(int)))
}
}

Expand Down
Loading