diff --git a/aws/resource_aws_ssm_association.go b/aws/resource_aws_ssm_association.go index e376c715f7d..d6d82021f2a 100644 --- a/aws/resource_aws_ssm_association.go +++ b/aws/resource_aws_ssm_association.go @@ -73,7 +73,6 @@ func resourceAwsSsmAssociation() *schema.Resource { "targets": { Type: schema.TypeList, Optional: true, - ForceNew: true, Computed: true, MaxItems: 5, Elem: &schema.Resource{ @@ -213,6 +212,10 @@ func resourceAwsSsmAssocationUpdate(d *schema.ResourceData, meta interface{}) er associationInput.OutputLocation = expandSSMAssociationOutputLocation(d.Get("output_location").([]interface{})) } + if d.HasChange("targets") { + associationInput.Targets = expandAwsSsmTargets(d) + } + _, err := ssmconn.UpdateAssociation(associationInput) if err != nil { return errwrap.Wrapf("[ERROR] Error updating SSM association: {{err}}", err) diff --git a/aws/resource_aws_ssm_association_test.go b/aws/resource_aws_ssm_association_test.go index 4186e29e456..5fa05de6fad 100644 --- a/aws/resource_aws_ssm_association_test.go +++ b/aws/resource_aws_ssm_association_test.go @@ -31,46 +31,65 @@ func TestAccAWSSSMAssociation_basic(t *testing.T) { func TestAccAWSSSMAssociation_withTargets(t *testing.T) { name := acctest.RandString(10) + oneTarget := ` + targets { + key = "tag:Name" + values = ["acceptanceTest"] + }` + twoTargets := ` + targets { + key = "tag:Name" + values = ["acceptanceTest"] + } + targets { + key = "tag:ExtraName" + values = ["acceptanceTest"] + }` resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSSSMAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSSMAssociationBasicConfigWithTargets(name), + Config: testAccAWSSSMAssociationBasicConfigWithTargets(name, oneTarget), Check: resource.ComposeTestCheckFunc( testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"), + resource.TestCheckResourceAttr( + "aws_ssm_association.foo", "targets.#", "1"), resource.TestCheckResourceAttr( "aws_ssm_association.foo", "targets.0.key", "tag:Name"), resource.TestCheckResourceAttr( "aws_ssm_association.foo", "targets.0.values.0", "acceptanceTest"), ), }, - }, - }) -} - -func TestAccAWSSSMAssociation_withMultipleTargets(t *testing.T) { - name := acctest.RandString(10) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSSSMAssociationDestroy, - Steps: []resource.TestStep{ { - Config: testAccAWSSSMAssociationBasicConfigWithMultipleTargets(name), + Config: testAccAWSSSMAssociationBasicConfigWithTargets(name, twoTargets), Check: resource.ComposeTestCheckFunc( testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"), + resource.TestCheckResourceAttr( + "aws_ssm_association.foo", "targets.#", "2"), resource.TestCheckResourceAttr( "aws_ssm_association.foo", "targets.0.key", "tag:Name"), resource.TestCheckResourceAttr( "aws_ssm_association.foo", "targets.0.values.0", "acceptanceTest"), resource.TestCheckResourceAttr( - "aws_ssm_association.foo", "targets.1.key", "tag:Environment"), + "aws_ssm_association.foo", "targets.1.key", "tag:ExtraName"), resource.TestCheckResourceAttr( "aws_ssm_association.foo", "targets.1.values.0", "acceptanceTest"), ), }, + { + Config: testAccAWSSSMAssociationBasicConfigWithTargets(name, oneTarget), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"), + resource.TestCheckResourceAttr( + "aws_ssm_association.foo", "targets.#", "1"), + resource.TestCheckResourceAttr( + "aws_ssm_association.foo", "targets.0.key", "tag:Name"), + resource.TestCheckResourceAttr( + "aws_ssm_association.foo", "targets.0.values.0", "acceptanceTest"), + ), + }, }, }) } @@ -359,10 +378,10 @@ resource "aws_ssm_association" "foo" { }`, rName) } -func testAccAWSSSMAssociationBasicConfigWithTargets(rName string) string { +func testAccAWSSSMAssociationBasicConfigWithTargets(rName, targetsStr string) string { return fmt.Sprintf(` resource "aws_ssm_document" "foo_document" { - name = "test_document_association-%s", + name = "test_document_association-%s" document_type = "Command" content = <