Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_ssm_association: Allow for multiple targets #2297

Merged
merged 4 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add steps checking that the targets are well set in the state?

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