diff --git a/go.mod b/go.mod index 90071ce15dda..4584ff580c95 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.20 require ( github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c github.com/YakDriver/regexache v0.23.0 - github.com/aws/aws-sdk-go v1.47.1 + github.com/aws/aws-sdk-go v1.47.3 github.com/aws/aws-sdk-go-v2 v1.22.1 - github.com/aws/aws-sdk-go-v2/config v1.21.0 - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.1 - github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.0 + github.com/aws/aws-sdk-go-v2/config v1.22.0 + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 + github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.1 github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.23.0 github.com/aws/aws-sdk-go-v2/service/account v1.13.0 github.com/aws/aws-sdk-go-v2/service/acm v1.21.0 @@ -65,6 +65,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/servicequotas v1.18.0 github.com/aws/aws-sdk-go-v2/service/sesv2 v1.23.0 github.com/aws/aws-sdk-go-v2/service/signer v1.18.0 + github.com/aws/aws-sdk-go-v2/service/sns v1.25.0 github.com/aws/aws-sdk-go-v2/service/sqs v1.26.0 github.com/aws/aws-sdk-go-v2/service/ssm v1.42.0 github.com/aws/aws-sdk-go-v2/service/ssmcontacts v1.19.0 @@ -77,6 +78,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/workspaces v1.33.0 github.com/aws/aws-sdk-go-v2/service/xray v1.22.0 github.com/beevik/etree v1.2.0 + github.com/davecgh/go-spew v1.1.1 github.com/gertd/go-pluralize v0.2.1 github.com/google/go-cmp v0.6.0 github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.21.0 @@ -123,7 +125,7 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.15.0 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.15.1 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 // indirect diff --git a/go.sum b/go.sum index cd069fb61365..fdc6c79cd0d6 100644 --- a/go.sum +++ b/go.sum @@ -22,21 +22,21 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmms github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.47.1 h1:j9ih0Ashcw8tQcnfqNimBM8ARQ/CMpoBwjKue1D6Fuk= -github.com/aws/aws-sdk-go v1.47.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.47.3 h1:e0H6NFXiniCpR8Lu3lTphVdRaeRCDLAeRyTHd1tJSd8= +github.com/aws/aws-sdk-go v1.47.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM= github.com/aws/aws-sdk-go-v2 v1.22.1 h1:sjnni/AuoTXxHitsIdT0FwmqUuNUuHtufcVDErVFT9U= github.com/aws/aws-sdk-go-v2 v1.22.1/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 h1:hHgLiIrTRtddC0AKcJr5s7i/hLgcpTt+q/FKxf1Zayk= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0/go.mod h1:w4I/v3NOWgD+qvs1NPEwhd++1h3XPHFaVxasfY6HlYQ= -github.com/aws/aws-sdk-go-v2/config v1.21.0 h1:BZEX5S6hkrAJ9rJn2hEMWIMkg+l1RC7gBQ84qkb0Cp0= -github.com/aws/aws-sdk-go-v2/config v1.21.0/go.mod h1:DMs4GYoTUo21V0cuDvwbdRb6coTcJ/EJxD7/WYZOinA= -github.com/aws/aws-sdk-go-v2/credentials v1.15.0 h1:gSRUMOU/wxxf89+4XYg0hYwOmcgdA0bohb7A/5nO+oE= -github.com/aws/aws-sdk-go-v2/credentials v1.15.0/go.mod h1:2zRQYW9jm3t18Ku+qP/107djyjAL7Ght6eBTWiNF/5c= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.1 h1:PYlUVUJRnXf2QU7IS+WLNSoU42f/oYRAmpwvXRH0Zq4= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.1/go.mod h1:wLyMIo/zPOhQhPXTddpfdkSleyigtFi8iMnC+2m/SK4= -github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.0 h1:LPTcGCwO6bup9pTuOmYFXlcocpMX8PPO+TIB7CtSVnI= -github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.0/go.mod h1:QJXFEiHtNvgiOuBx9cyK6hC28xTB7mQ/iya6Xr1Fu7Y= +github.com/aws/aws-sdk-go-v2/config v1.22.0 h1:9Mm99OalzZRz0ab5fpodMoHBApHS6pqRNp3M9NmzvDg= +github.com/aws/aws-sdk-go-v2/config v1.22.0/go.mod h1:2eWgw5lps8fKI7LZVTrRTYP6HE6k/uEFUuTSHfXwqP0= +github.com/aws/aws-sdk-go-v2/credentials v1.15.1 h1:hmf6lAm9hk7uLCfapZn/jL05lm6Uwdbn1B0fgjyuf4M= +github.com/aws/aws-sdk-go-v2/credentials v1.15.1/go.mod h1:QTcHga3ZbQOneJuxmGBOCxiClxmp+TlvmjFexAnJ790= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 h1:gIeH4+o1MN/caGBWjoGQTUTIu94xD6fI5B2+TcwBf70= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2/go.mod h1:wLyMIo/zPOhQhPXTddpfdkSleyigtFi8iMnC+2m/SK4= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.1 h1:ULswbgGNVrW8zEhkCNwrwXrs1mUvy2JTqWaCRsD2ZZw= +github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.1/go.mod h1:pAXgsDPk1rRwwfkz8/9ISO75vXEHqTGIgbLhGqqQ1GY= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ= github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 h1:fi1ga6WysOyYb5PAf3Exd6B5GiSNpnZim4h1rhlBqx0= github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1/go.mod h1:V5CY8wNurvPUibTi9mwqUqpiFZ5LnioKWIFUDtIzdI8= @@ -173,6 +173,8 @@ github.com/aws/aws-sdk-go-v2/service/sesv2 v1.23.0 h1:+ZEjKybjvhVSJO+1fjOO20Qj7U github.com/aws/aws-sdk-go-v2/service/sesv2 v1.23.0/go.mod h1:6yFv/JdEBgJSq+bheEas8X6gK7CmmcIXJIoEAur/Zqk= github.com/aws/aws-sdk-go-v2/service/signer v1.18.0 h1:IO1mEA0wlUNWP//4Xsz2eLsYPKpICISYAU0AMgpjskk= github.com/aws/aws-sdk-go-v2/service/signer v1.18.0/go.mod h1:X7ARQoz5JA0cwtWH3MZKvBuTf10nxc78Wyz0oi7j3QI= +github.com/aws/aws-sdk-go-v2/service/sns v1.25.0 h1:jLJACSO/+RZZ5KWPSt6Fw0+6mUTJMTyAb0+iLaB256Y= +github.com/aws/aws-sdk-go-v2/service/sns v1.25.0/go.mod h1:TaJ0nsVcYe9tq+m/VH721tzquF8YusAgcwD5xeppVNw= github.com/aws/aws-sdk-go-v2/service/sqs v1.26.0 h1:21QmEZkOnaJ4SPRFhhN+8MV5ewb0j1lxTg+RPp0mUeE= github.com/aws/aws-sdk-go-v2/service/sqs v1.26.0/go.mod h1:E02a07/HTyJEHFpp+WMRh33xuNVdsd8WCbLlODeT4lU= github.com/aws/aws-sdk-go-v2/service/ssm v1.42.0 h1:a0cfLtzrmSy6mnpeg6gh5pSg9hUgn4lMz38p0jAdAuY= diff --git a/internal/service/batch/job_definition_test.go b/internal/service/batch/job_definition_test.go index 71906baf8df5..a2b86c93eb8c 100644 --- a/internal/service/batch/job_definition_test.go +++ b/internal/service/batch/job_definition_test.go @@ -176,7 +176,7 @@ func TestAccBatchJobDefinition_disappears(t *testing.T) { }) } -func TestAccBatchJobDefinition_containerPropertiesFargateDefaults(t *testing.T) { +func TestAccBatchJobDefinition_ContainerProperties_fargateDefaults(t *testing.T) { ctx := acctest.Context(t) var jd batch.JobDefinition rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -189,7 +189,7 @@ func TestAccBatchJobDefinition_containerPropertiesFargateDefaults(t *testing.T) CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccJobDefinitionConfig_capabilitiesFargateContainerPropertiesDefaults(rName), + Config: testAccJobDefinitionConfig_ContainerProperties_defaultsFargate(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckJobDefinitionExists(ctx, resourceName, &jd), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "batch", regexache.MustCompile(fmt.Sprintf(`job-definition/%s:\d+`, rName))), @@ -221,7 +221,7 @@ func TestAccBatchJobDefinition_containerPropertiesFargateDefaults(t *testing.T) }) } -func TestAccBatchJobDefinition_containerPropertiesFargate(t *testing.T) { +func TestAccBatchJobDefinition_ContainerProperties_fargate(t *testing.T) { ctx := acctest.Context(t) var jd batch.JobDefinition rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -266,7 +266,7 @@ func TestAccBatchJobDefinition_containerPropertiesFargate(t *testing.T) { }) } -func TestAccBatchJobDefinition_containerPropertiesEC2(t *testing.T) { +func TestAccBatchJobDefinition_ContainerProperties_EC2(t *testing.T) { ctx := acctest.Context(t) var jd batch.JobDefinition compare := batch.JobDefinition{ @@ -318,7 +318,7 @@ func TestAccBatchJobDefinition_containerPropertiesEC2(t *testing.T) { CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccJobDefinitionConfig_containerPropertiesAdvanced(rName), + Config: testAccJobDefinitionConfig_ContainerProperties_advanced(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckJobDefinitionExists(ctx, resourceName, &jd), testAccCheckJobDefinitionAttributes(&jd, &compare), @@ -379,7 +379,7 @@ func TestAccBatchJobDefinition_tags(t *testing.T) { }) } -func TestAccBatchJobDefinition_containerPropertiesEC2EmptyField(t *testing.T) { +func TestAccBatchJobDefinition_ContainerProperties_EC2EmptyField(t *testing.T) { ctx := acctest.Context(t) var jd batch.JobDefinition rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -395,7 +395,7 @@ func TestAccBatchJobDefinition_containerPropertiesEC2EmptyField(t *testing.T) { CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccJobDefinitionConfig_containerProperties_emptyField(rName), + Config: testAccJobDefinitionConfig_ContainerProperties_emptyField(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckJobDefinitionExists(ctx, resourceName, &jd), acctest.CheckResourceAttrJMES(resourceName, "container_properties", "length(environment)", "1"), @@ -481,59 +481,59 @@ func TestAccBatchJobDefinition_NodeProperties_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - }, - }) -} - -func TestAccBatchJobDefinition_NodePropertiesupdateForcesNewResource(t *testing.T) { - ctx := acctest.Context(t) - var before, after batch.JobDefinition - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_batch_job_definition.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, batch.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccJobDefinitionConfig_nodePropertiesAdvanced(rName), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckJobDefinitionExists(ctx, resourceName, &before), - testAccCheckJobDefinitionAttributes(&before, nil), - ), - }, { - Config: testAccJobDefinitionConfig_nodePropertiesAdvancedUpdate(rName), + Config: testAccJobDefinitionConfig_NodeProperties_advancedUpdate(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckJobDefinitionExists(ctx, resourceName, &after), - testAccCheckJobDefinitionRecreated(t, &before, &after), + testAccCheckJobDefinitionExists(ctx, resourceName, &jd), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "batch", regexache.MustCompile(fmt.Sprintf(`job-definition/%s:\d+`, rName))), + acctest.CheckResourceAttrEquivalentJSON(resourceName, "node_properties", `{ + "mainNode": 1, + "nodeRangeProperties": [ + { + "container": { + "command": ["ls","-la"], + "environment": [], + "image": "busybox", + "memory": 512, + "mountPoints": [], + "resourceRequirements": [], + "secrets": [], + "ulimits": [], + "vcpus": 1, + "volumes": [] + }, + "targetNodes": "0:" + }, + { + "container": { + "command": ["echo","test"], + "environment": [], + "image": "busybox", + "memory": 128, + "mountPoints": [], + "resourceRequirements": [], + "secrets": [], + "ulimits": [], + "vcpus": 1, + "volumes": [] + }, + "targetNodes": "1:" + } + ], + "numNodes": 4 + }`), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(resourceName, "platform_capabilities.#", "0"), + resource.TestCheckResourceAttr(resourceName, "propagate_tags", "false"), + resource.TestCheckResourceAttr(resourceName, "retry_strategy.#", "0"), + resource.TestCheckResourceAttr(resourceName, "revision", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(resourceName, "tags_all.%", "0"), + resource.TestCheckResourceAttr(resourceName, "timeout.#", "1"), + resource.TestCheckResourceAttr(resourceName, "type", "multinode"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccBatchJobDefinition_createTypeContainerWithBothProperties(t *testing.T) { - ctx := acctest.Context(t) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, batch.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccJobDefinitionConfig_createTypeContainerWithBothProperties(rName), - ExpectError: regexache.MustCompile("No `node_properties` can be specified when `type` is \"container\""), - }, }, }) } @@ -549,14 +549,14 @@ func TestAccBatchJobDefinition_createTypeContainerWithNodeProperties(t *testing. CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccJobDefinitionConfig_createTypeContainerWithNodeProperties(rName), + Config: testAccJobDefinitionConfig_NodeProperties_createTypeContainerErr(rName), ExpectError: regexache.MustCompile("No `node_properties` can be specified when `type` is \"container\""), }, }, }) } -func TestAccBatchJobDefinition_createTypeMultiNodeWithBothProperties(t *testing.T) { +func TestAccBatchJobDefinition_ContainerProperties_createTypeMultiNodeErr(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -567,25 +567,7 @@ func TestAccBatchJobDefinition_createTypeMultiNodeWithBothProperties(t *testing. CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccJobDefinitionConfig_createTypeMultiNodeWithBothProperties(rName), - ExpectError: regexache.MustCompile("No `container_properties` can be specified when `type` is \"multinode\""), - }, - }, - }) -} - -func TestAccBatchJobDefinition_createTypeMultiNodeWithContainerProperties(t *testing.T) { - ctx := acctest.Context(t) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, batch.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckJobDefinitionDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccJobDefinitionConfig_createTypeMultiNodeWithContainerProperties(rName), + Config: testAccJobDefinitionConfig_ContainerProperties_createTypeMultiNodeErr(rName), ExpectError: regexache.MustCompile("No `container_properties` can be specified when `type` is \"multinode\""), }, }, @@ -617,6 +599,34 @@ func testAccCheckJobDefinitionExists(ctx context.Context, n string, jd *batch.Jo } } +func testAccCheckJobDefinitionDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).BatchConn(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_batch_job_definition" { + continue + } + + re := regexp.MustCompile(`job-definition/(.*?):`) + name := re.FindStringSubmatch(rs.Primary.ID)[1] + + jds, err := tfbatch.ListActiveJobDefinitionByName(ctx, conn, name) + + if count := len(jds); count == 0 { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("Batch Job Definition %s has revisions that still exist", name) + } + return nil + } +} + func testAccCheckJobDefinitionAttributes(jd *batch.JobDefinition, compare *batch.JobDefinition) resource.TestCheckFunc { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { @@ -648,35 +658,7 @@ func testAccCheckJobDefinitionAttributes(jd *batch.JobDefinition, compare *batch } } -func testAccCheckJobDefinitionDestroy(ctx context.Context) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).BatchConn(ctx) - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_batch_job_definition" { - continue - } - - re := regexp.MustCompile(`job-definition/(.*?):`) - name := re.FindStringSubmatch(rs.Primary.ID)[1] - - jds, err := tfbatch.ListActiveJobDefinitionByName(ctx, conn, name) - - if count := len(jds); count == 0 { - continue - } - - if err != nil { - return err - } - - return fmt.Errorf("Batch Job Definition %s has revisions that still exist", name) - } - return nil - } -} - -func testAccJobDefinitionConfig_containerPropertiesAdvanced(rName string) string { +func testAccJobDefinitionConfig_ContainerProperties_advanced(rName string) string { return fmt.Sprintf(` resource "aws_batch_job_definition" "test" { name = %[1]q @@ -737,49 +719,6 @@ CONTAINER_PROPERTIES `, rName) } -func testAccJobDefinitionConfig_containerPropertiesAdvancedUpdate(rName string) string { - return fmt.Sprintf(` -resource "aws_batch_job_definition" "test" { - name = %[1]q - type = "container" - container_properties = <