Skip to content

Commit

Permalink
resource/aws_ssm_association: Allow for multiple targets (#2297)
Browse files Browse the repository at this point in the history
* Allow up to 5 targets

* Update docs

* Add a test with multiple targets

* Test that targets are well set in the state
  • Loading branch information
tom-henderson authored and Ninir committed Jan 10, 2018
1 parent ec94bd9 commit 74c7ace
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_ssm_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func resourceAwsSsmAssociation() *schema.Resource {
Optional: true,
ForceNew: true,
Computed: true,
MaxItems: 1,
MaxItems: 5,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Expand Down
68 changes: 68 additions & 0 deletions aws/resource_aws_ssm_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ func TestAccAWSSSMAssociation_withTargets(t *testing.T) {
Config: testAccAWSSSMAssociationBasicConfigWithTargets(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"),
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),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"),
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"),
resource.TestCheckResourceAttr(
"aws_ssm_association.foo", "targets.1.values.0", "acceptanceTest"),
),
},
},
Expand Down Expand Up @@ -365,6 +394,45 @@ resource "aws_ssm_association" "foo" {
}`, rName)
}

func testAccAWSSSMAssociationBasicConfigWithMultipleTargets(rName string) string {
return fmt.Sprintf(`
resource "aws_ssm_document" "foo_document" {
name = "test_document_association-%s",
document_type = "Command"
content = <<DOC
{
"schemaVersion": "1.2",
"description": "Check ip configuration of a Linux instance.",
"parameters": {
},
"runtimeConfig": {
"aws:runShellScript": {
"properties": [
{
"id": "0.aws:runShellScript",
"runCommand": ["ifconfig"]
}
]
}
}
}
DOC
}
resource "aws_ssm_association" "foo" {
name = "${aws_ssm_document.foo_document.name}",
targets {
key = "tag:Name"
values = ["acceptanceTest"]
}
targets {
key = "tag:Environment"
values = ["acceptanceTest"]
}
}`, rName)
}

func testAccAWSSSMAssociationBasicConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_security_group" "tf_test_foo" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/ssm_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The following arguments are supported:
* `output_location` - (Optional) An output location block. Output Location is documented below.
* `parameters` - (Optional) A block of arbitrary string parameters to pass to the SSM document.
* `schedule_expression` - (Optional) A cron expression when the association will be applied to the target(s).
* `targets` - (Optional) A block containing the targets of the SSM association. Targets are documented below.
* `targets` - (Optional) A block containing the targets of the SSM association. Targets are documented below. AWS currently supports a maximum of 5 targets.

Output Location (`output_location`) is an S3 bucket where you want to store the results of this association:

Expand Down

0 comments on commit 74c7ace

Please sign in to comment.