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/aws_ecs_task_definition: add track_latest attribute #30154

Merged
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/30154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ecs_task_definition: Add `track_latest` argument
```
15 changes: 13 additions & 2 deletions internal/service/ecs/task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ func ResourceTaskDefinition() *schema.Resource {
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"track_latest": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"volume": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -562,9 +567,14 @@ func resourceTaskDefinitionRead(ctx context.Context, d *schema.ResourceData, met
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ECSConn(ctx)

trackedTaskDefinition := d.Get("arn").(string)
if _, ok := d.GetOk("track_latest"); ok {
trackedTaskDefinition = d.Get("family").(string)
}

input := ecs.DescribeTaskDefinitionInput{
TaskDefinition: aws.String(d.Get("arn").(string)),
Include: []*string{aws.String(ecs.TaskDefinitionFieldTags)},
Include: aws.StringSlice([]string{ecs.TaskDefinitionFieldTags}),
TaskDefinition: aws.String(trackedTaskDefinition),
}

out, err := conn.DescribeTaskDefinitionWithContext(ctx, &input)
Expand Down Expand Up @@ -597,6 +607,7 @@ func resourceTaskDefinitionRead(ctx context.Context, d *schema.ResourceData, met
d.Set("arn_without_revision", StripRevision(aws.StringValue(taskDefinition.TaskDefinitionArn)))
d.Set("family", taskDefinition.Family)
d.Set("revision", taskDefinition.Revision)
d.Set("track_latest", d.Get("track_latest"))

// Sort the lists of environment variables as they come in, so we won't get spurious reorderings in plans
// (diff is suppressed if the environment variables haven't changed, but they still show in the plan if
Expand Down
143 changes: 115 additions & 28 deletions internal/service/ecs/task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestAccECSTaskDefinition_basic(t *testing.T) {
testAccCheckTaskDefinitionExists(ctx, resourceName, &def),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "ecs", regexache.MustCompile(`task-definition/.+`)),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn_without_revision", "ecs", regexache.MustCompile(`task-definition/.+`)),
resource.TestCheckResourceAttr(resourceName, "track_latest", "false"),
),
},
{
Expand All @@ -99,7 +100,7 @@ func TestAccECSTaskDefinition_basic(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -129,7 +130,7 @@ func TestAccECSTaskDefinition_scratchVolume(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -172,7 +173,7 @@ func TestAccECSTaskDefinition_DockerVolume_basic(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -207,7 +208,7 @@ func TestAccECSTaskDefinition_DockerVolume_minimal(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestAccECSTaskDefinition_runtimePlatform(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -275,7 +276,7 @@ func TestAccECSTaskDefinition_Fargate_runtimePlatform(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -308,7 +309,7 @@ func TestAccECSTaskDefinition_Fargate_runtimePlatformWithoutArch(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -343,7 +344,7 @@ func TestAccECSTaskDefinition_EFSVolume_minimal(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -379,7 +380,7 @@ func TestAccECSTaskDefinition_EFSVolume_basic(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -417,7 +418,7 @@ func TestAccECSTaskDefinition_EFSVolume_transitEncryptionMinimal(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -455,7 +456,7 @@ func TestAccECSTaskDefinition_EFSVolume_transitEncryption(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -492,7 +493,7 @@ func TestAccECSTaskDefinition_EFSVolume_transitEncryptionDisabled(t *testing.T)
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -533,7 +534,7 @@ func TestAccECSTaskDefinition_EFSVolume_accessPoint(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -581,7 +582,7 @@ func TestAccECSTaskDefinition_fsxWinFileSystem(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -644,7 +645,7 @@ func TestAccECSTaskDefinition_service(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -673,7 +674,7 @@ func TestAccECSTaskDefinition_taskRoleARN(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -703,7 +704,7 @@ func TestAccECSTaskDefinition_networkMode(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -733,7 +734,7 @@ func TestAccECSTaskDefinition_ipcMode(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -763,7 +764,7 @@ func TestAccECSTaskDefinition_pidMode(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -794,7 +795,7 @@ func TestAccECSTaskDefinition_constraint(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -830,7 +831,7 @@ func TestAccECSTaskDefinition_changeVolumesForcesNewResource(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -860,7 +861,7 @@ func TestAccECSTaskDefinition_arrays(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -892,7 +893,7 @@ func TestAccECSTaskDefinition_Fargate_basic(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
{
ExpectNonEmptyPlan: false,
Expand Down Expand Up @@ -931,7 +932,7 @@ func TestAccECSTaskDefinition_Fargate_ephemeralStorage(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -960,7 +961,7 @@ func TestAccECSTaskDefinition_executionRole(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -1020,7 +1021,7 @@ func TestAccECSTaskDefinition_tags(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
{
Config: testAccTaskDefinitionConfig_tags2(rName, "key1", "value1updated", "key2", "value2"),
Expand Down Expand Up @@ -1076,7 +1077,7 @@ func TestAccECSTaskDefinition_proxy(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand Down Expand Up @@ -1106,7 +1107,7 @@ func TestAccECSTaskDefinition_inferenceAccelerator(t *testing.T) {
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
Expand All @@ -1130,6 +1131,38 @@ func TestAccECSTaskDefinition_invalidContainerDefinition(t *testing.T) {
})
}

func TestAccECSTaskDefinition_trackLatest(t *testing.T) {
ctx := acctest.Context(t)
var def ecs.TaskDefinition
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_ecs_task_definition.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ecs.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTaskDefinitionDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTaskDefinitionConfig_trackLatest(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTaskDefinitionExists(ctx, resourceName, &def),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "ecs", regexache.MustCompile(`task-definition/.+`)),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn_without_revision", "ecs", regexache.MustCompile(`task-definition/.+`)),
resource.TestCheckResourceAttr(resourceName, "track_latest", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy", "track_latest"},
},
},
})
}

func testAccTaskDefinitionConfig_proxyConfiguration(rName string, containerName string, proxyType string,
ignoredUid string, ignoredGid string, appPorts string, proxyIngressPort string, proxyEgressPort string,
egressIgnoredPorts string, egressIgnoredIPs string) string {
Expand Down Expand Up @@ -2861,3 +2894,57 @@ TASK_DEFINITION
}
`, rName)
}

func testAccTaskDefinitionConfig_trackLatest(rName string) string {
return fmt.Sprintf(`
resource "aws_ecs_task_definition" "test" {
family = %[1]q

container_definitions = <<TASK_DEFINITION
[
{
"cpu": 10,
"command": ["sleep", "10"],
"entryPoint": ["/"],
"environment": [
{"name": "VARNAME", "value": "VARVAL"}
],
"essential": true,
"image": "jenkins",
"links": ["mongodb"],
"memory": 128,
"name": "jenkins",
"portMappings": [
{
"containerPort": 80,
"hostPort": 8080
}
]
},
{
"cpu": 10,
"command": ["sleep", "10"],
"entryPoint": ["/"],
"essential": true,
"image": "mongodb",
"memory": 128,
"name": "mongodb",
"portMappings": [
{
"containerPort": 28017,
"hostPort": 28017
}
]
}
]
TASK_DEFINITION

volume {
name = "jenkins-home"
host_path = "/ecs/jenkins-home"
}

track_latest = true
}
`, rName)
}
Loading
Loading