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

f-aws_ecs_account_setting_default support for fargateTaskRetirementWaitPeriod #37018

Merged
merged 10 commits into from
May 11, 2024
3 changes: 3 additions & 0 deletions .changelog/37018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ecs_account_setting_default: Add support for `fargateTaskRetirementWaitPeriod` value in `Name` argument
```
8 changes: 7 additions & 1 deletion internal/service/ecs/account_setting_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,17 @@ func resourceAccountSettingDefaultDelete(ctx context.Context, d *schema.Resource
conn := meta.(*conns.AWSClient).ECSConn(ctx)

settingName := d.Get(names.AttrName).(string)
settingValue := "disabled"

//Default value: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-maintenance.html#task-retirement-change
if settingName == ecs.SettingNameFargateTaskRetirementWaitPeriod {
settingValue = fargateTaskRetirementWaitPeriodValue
}

log.Printf("[WARN] Disabling ECS Account Setting Default %s", settingName)
input := ecs.PutAccountSettingDefaultInput{
Name: aws.String(settingName),
Value: aws.String("disabled"),
Value: aws.String(settingValue),
}

_, err := conn.PutAccountSettingDefaultWithContext(ctx, &input)
Expand Down
51 changes: 45 additions & 6 deletions internal/service/ecs/account_setting_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ func TestAccECSAccountSettingDefault_serial(t *testing.T) {
t.Parallel()

testCases := map[string]func(*testing.T){
"containerInstanceLongARNFormat": testAccAccountSettingDefault_containerInstanceLongARNFormat,
"serviceLongARNFormat": testAccAccountSettingDefault_serviceLongARNFormat,
"taskLongARNFormat": testAccAccountSettingDefault_taskLongARNFormat,
"vpcTrunking": testAccAccountSettingDefault_vpcTrunking,
"containerInsights": testAccAccountSettingDefault_containerInsights,
"containerInstanceLongARNFormat": testAccAccountSettingDefault_containerInstanceLongARNFormat,
"serviceLongARNFormat": testAccAccountSettingDefault_serviceLongARNFormat,
"taskLongARNFormat": testAccAccountSettingDefault_taskLongARNFormat,
"vpcTrunking": testAccAccountSettingDefault_vpcTrunking,
"containerInsights": testAccAccountSettingDefault_containerInsights,
"fargateTaskRetirementWaitPeriod": testAccAccountSettingDefault_fargateTaskRetirementWaitPeriod,
}

acctest.RunSerialTests1Level(t, testCases, 0)
Expand Down Expand Up @@ -178,6 +179,35 @@ func testAccAccountSettingDefault_containerInsights(t *testing.T) {
})
}

func testAccAccountSettingDefault_fargateTaskRetirementWaitPeriod(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_ecs_account_setting_default.test"
settingName := ecs.SettingNameFargateTaskRetirementWaitPeriod

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.ECSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAccountSettingDefaultDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAccountSettingDefaultConfig_fargateTaskRetirementWaitPeriod(settingName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, names.AttrName, "fargateTaskRetirementWaitPeriod"),
resource.TestCheckResourceAttr(resourceName, names.AttrValue, "14"),
acctest.MatchResourceAttrGlobalARN(resourceName, "principal_arn", "iam", regexache.MustCompile("root")),
),
},
{
ResourceName: resourceName,
ImportStateId: "fargateTaskRetirementWaitPeriod",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAccountSettingDefaultDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).ECSConn(ctx)
Expand Down Expand Up @@ -205,7 +235,7 @@ func testAccCheckAccountSettingDefaultDestroy(ctx context.Context) resource.Test
}

for _, value := range resp.Settings {
if aws.StringValue(value.Value) != "disabled" {
if aws.StringValue(value.Value) != "disabled" && aws.StringValue(value.Value) != "7" {
switch name {
case ecs.SettingNameContainerInstanceLongArnFormat:
return nil
Expand All @@ -232,3 +262,12 @@ resource "aws_ecs_account_setting_default" "test" {
}
`, settingName)
}

func testAccAccountSettingDefaultConfig_fargateTaskRetirementWaitPeriod(settingName string) string {
return fmt.Sprintf(`
resource "aws_ecs_account_setting_default" "test" {
name = %[1]q
value = "14"
}
`, settingName)
}
4 changes: 4 additions & 0 deletions internal/service/ecs/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ const (
clusterStatusInactive = "INACTIVE"
clusterStatusProvisioning = "PROVISIONING"
)

const (
fargateTaskRetirementWaitPeriodValue = "7"
)
Loading