Skip to content

Commit

Permalink
Merge pull request #18336 from leonsmith/f-aws_batch_job_definition-p…
Browse files Browse the repository at this point in the history
…ropagate-tags

resource/aws_batch_job_definition: Add propagate_tags argument
  • Loading branch information
ewbankkit authored Apr 19, 2021
2 parents d09f5a7 + 41f2c4e commit 67df8c8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/18336.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_batch_job_definition: Add `propagate_tags` argument
```
8 changes: 8 additions & 0 deletions aws/resource_aws_batch_job_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func resourceAwsBatchJobDefinition() *schema.Resource {
},
},
"tags": tagsSchema(),
"propagate_tags": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Default: false,
},
"timeout": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -122,6 +128,7 @@ func resourceAwsBatchJobDefinitionCreate(d *schema.ResourceData, meta interface{
input := &batch.RegisterJobDefinitionInput{
JobDefinitionName: aws.String(name),
Type: aws.String(d.Get("type").(string)),
PropagateTags: aws.Bool(d.Get("propagate_tags").(bool)),
}

if v, ok := d.GetOk("container_properties"); ok {
Expand Down Expand Up @@ -195,6 +202,7 @@ func resourceAwsBatchJobDefinitionRead(d *schema.ResourceData, meta interface{})
d.Set("name", jobDefinition.JobDefinitionName)
d.Set("parameters", aws.StringValueMap(jobDefinition.Parameters))
d.Set("platform_capabilities", aws.StringValueSlice(jobDefinition.PlatformCapabilities))
d.Set("propagate_tags", jobDefinition.PropagateTags)

if err := d.Set("retry_strategy", flattenBatchRetryStrategy(jobDefinition.RetryStrategy)); err != nil {
return fmt.Errorf("error setting retry_strategy: %w", err)
Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_batch_job_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestAccAWSBatchJobDefinition_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "platform_capabilities.#", "0"),
resource.TestCheckResourceAttr(resourceName, "propagate_tags", "false"),
resource.TestCheckResourceAttr(resourceName, "retry_strategy.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "revision"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -151,6 +152,7 @@ func TestAccAWSBatchJobDefinition_PlatformCapabilities_EC2(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "platform_capabilities.#", "1"),
resource.TestCheckTypeSetElemAttr(resourceName, "platform_capabilities.*", "EC2"),
resource.TestCheckResourceAttr(resourceName, "propagate_tags", "false"),
resource.TestCheckResourceAttr(resourceName, "retry_strategy.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "revision"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -188,6 +190,7 @@ func TestAccAWSBatchJobDefinition_PlatformCapabilities_Fargate(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "platform_capabilities.#", "1"),
resource.TestCheckTypeSetElemAttr(resourceName, "platform_capabilities.*", "FARGATE"),
resource.TestCheckResourceAttr(resourceName, "propagate_tags", "false"),
resource.TestCheckResourceAttr(resourceName, "retry_strategy.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "revision"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -345,6 +348,38 @@ func TestAccAWSBatchJobDefinition_Tags(t *testing.T) {
})
}

func TestAccAWSBatchJobDefinition_PropagateTags(t *testing.T) {
var jd batch.JobDefinition
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_batch_job_definition.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSBatch(t) },
ErrorCheck: testAccErrorCheck(t, batch.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckBatchJobDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAccBatchJobDefinitionPropagateTags(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckBatchJobDefinitionExists(resourceName, &jd),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "batch", regexp.MustCompile(fmt.Sprintf(`job-definition/%s:\d+`, rName))),
resource.TestCheckResourceAttrSet(resourceName, "container_properties"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "platform_capabilities.#", "0"),
resource.TestCheckResourceAttr(resourceName, "propagate_tags", "true"),
resource.TestCheckResourceAttr(resourceName, "retry_strategy.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "revision"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "timeout.#", "0"),
resource.TestCheckResourceAttr(resourceName, "type", "container"),
),
},
},
})
}

func testAccCheckBatchJobDefinitionExists(n string, jd *batch.JobDefinition) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -647,3 +682,20 @@ resource "aws_batch_job_definition" "test" {
}
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
}

func testAccBatchJobDefinitionPropagateTags(rName string) string {
return fmt.Sprintf(`
resource "aws_batch_job_definition" "test" {
container_properties = jsonencode({
command = ["echo", "test"]
image = "busybox"
memory = 128
vcpus = 1
})
name = %[1]q
type = "container"
propagate_tags = true
}
`, rName)
}
5 changes: 3 additions & 2 deletions website/docs/r/batch_job_definition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ The following arguments are supported:
provided as a single valid JSON document. This parameter is required if the `type` parameter is `container`.
* `parameters` - (Optional) Specifies the parameter substitution placeholders to set in the job definition.
* `platform_capabilities` - (Optional) The platform capabilities required by the job definition. If no value is specified, it defaults to `EC2`. To run the job on Fargate resources, specify `FARGATE`.
* `propagate_tags` - (Optional) Specifies whether to propagate the tags from the job definition to the corresponding Amazon ECS task. Default is `false`.
* `retry_strategy` - (Optional) Specifies the retry strategy to use for failed jobs that are submitted with this job definition.
Maximum number of `retry_strategy` is `1`. Defined below.
* `tags` - (Optional) Key-value map of resource tags
* `tags` - (Optional) Key-value map of resource tags.
* `timeout` - (Optional) Specifies the timeout for jobs so that if a job runs longer, AWS Batch terminates the job. Maximum number of `timeout` is `1`. Defined below.
* `type` - (Required) The type of job definition. Must be `container`
* `type` - (Required) The type of job definition. Must be `container`.

## retry_strategy

Expand Down

0 comments on commit 67df8c8

Please sign in to comment.