From e4be09f01b26d53e58457b14330112cc8649378d Mon Sep 17 00:00:00 2001 From: Leon Smith <_@leonmarksmith.com> Date: Mon, 22 Mar 2021 19:51:49 +0000 Subject: [PATCH 1/5] resource/aws_batch_job_definition: Add propagate_tags argument Closes #17278 --- .changelog/18336.txt | 3 ++ aws/resource_aws_batch_job_definition.go | 7 ++++ aws/resource_aws_batch_job_definition_test.go | 39 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 .changelog/18336.txt diff --git a/.changelog/18336.txt b/.changelog/18336.txt new file mode 100644 index 000000000000..d63635476cca --- /dev/null +++ b/.changelog/18336.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_batch_job_definition: Add propagate_tags argument +``` \ No newline at end of file diff --git a/aws/resource_aws_batch_job_definition.go b/aws/resource_aws_batch_job_definition.go index e82a5b60a4c2..669c32005e77 100644 --- a/aws/resource_aws_batch_job_definition.go +++ b/aws/resource_aws_batch_job_definition.go @@ -81,6 +81,11 @@ func resourceAwsBatchJobDefinition() *schema.Resource { }, }, "tags": tagsSchema(), + "propagate_tags": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "timeout": { Type: schema.TypeList, Optional: true, @@ -122,6 +127,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 { @@ -195,6 +201,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) diff --git a/aws/resource_aws_batch_job_definition_test.go b/aws/resource_aws_batch_job_definition_test.go index 7f97aa8c496e..944758e55fa2 100644 --- a/aws/resource_aws_batch_job_definition_test.go +++ b/aws/resource_aws_batch_job_definition_test.go @@ -345,6 +345,28 @@ 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), + resource.TestCheckResourceAttr(resourceName, "propagate_tags", "true"), + ), + }, + }, + }) +} + func testAccCheckBatchJobDefinitionExists(n string, jd *batch.JobDefinition) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -647,3 +669,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) +} From 8c3a8d2ef74d2599a13d540de81aa19f6d4d983a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 19 Apr 2021 12:05:57 -0400 Subject: [PATCH 2/5] Format new argumnet name in CHANGELOG. --- .changelog/18336.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/18336.txt b/.changelog/18336.txt index d63635476cca..9a2317c00e75 100644 --- a/.changelog/18336.txt +++ b/.changelog/18336.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_batch_job_definition: Add propagate_tags argument +resource/aws_batch_job_definition: Add `propagate_tags` argument ``` \ No newline at end of file From ec1d0384aa270ef33fbe38b6af40f3b26eb5796f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 19 Apr 2021 12:07:23 -0400 Subject: [PATCH 3/5] r/aws_batch_job_definition: 'propagate_tags' is 'ForceNew'. --- aws/resource_aws_batch_job_definition.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_batch_job_definition.go b/aws/resource_aws_batch_job_definition.go index 669c32005e77..d31d97ecec6c 100644 --- a/aws/resource_aws_batch_job_definition.go +++ b/aws/resource_aws_batch_job_definition.go @@ -84,6 +84,7 @@ func resourceAwsBatchJobDefinition() *schema.Resource { "propagate_tags": { Type: schema.TypeBool, Optional: true, + ForceNew: true, Default: false, }, "timeout": { From 36150158dbde75132f7cced6c41cb5248cef267c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 19 Apr 2021 12:09:56 -0400 Subject: [PATCH 4/5] r/aws_batch_job_definition: Document 'propagate_tags'. --- website/docs/r/batch_job_definition.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/docs/r/batch_job_definition.html.markdown b/website/docs/r/batch_job_definition.html.markdown index 50483bdd018d..004fa387a8e6 100644 --- a/website/docs/r/batch_job_definition.html.markdown +++ b/website/docs/r/batch_job_definition.html.markdown @@ -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 From 41f2c4e2ccc2fe82912547487a13ccc266d9bf75 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 19 Apr 2021 12:14:35 -0400 Subject: [PATCH 5/5] r/aws_batch_job_definition: Verify that default value of 'propagate_tags' is false in acceptance tests. --- aws/resource_aws_batch_job_definition_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/aws/resource_aws_batch_job_definition_test.go b/aws/resource_aws_batch_job_definition_test.go index 944758e55fa2..a4496129dd53 100644 --- a/aws/resource_aws_batch_job_definition_test.go +++ b/aws/resource_aws_batch_job_definition_test.go @@ -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"), @@ -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"), @@ -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"), @@ -360,7 +363,17 @@ func TestAccAWSBatchJobDefinition_PropagateTags(t *testing.T) { 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"), ), }, },