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

Added ComplianceSeverity Argument #7852

Merged
merged 4 commits into from
Mar 17, 2019
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
21 changes: 21 additions & 0 deletions aws/resource_aws_ssm_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func resourceAwsSsmAssociation() *schema.Resource {
Expand Down Expand Up @@ -88,6 +89,17 @@ func resourceAwsSsmAssociation() *schema.Resource {
},
},
},
"compliance_severity": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
marcotesch marked this conversation as resolved.
Show resolved Hide resolved
ssm.ComplianceSeverityUnspecified,
ssm.ComplianceSeverityLow,
ssm.ComplianceSeverityMedium,
ssm.ComplianceSeverityHigh,
ssm.ComplianceSeverityCritical,
}, false),
},
},
}
}
Expand Down Expand Up @@ -129,6 +141,10 @@ func resourceAwsSsmAssociationCreate(d *schema.ResourceData, meta interface{}) e
associationInput.OutputLocation = expandSSMAssociationOutputLocation(v.([]interface{}))
}

if v, ok := d.GetOk("compliance_severity"); ok {
associationInput.ComplianceSeverity = aws.String(v.(string))
}

resp, err := ssmconn.CreateAssociation(associationInput)
if err != nil {
return fmt.Errorf("Error creating SSM association: %s", err)
Expand Down Expand Up @@ -174,6 +190,7 @@ func resourceAwsSsmAssociationRead(d *schema.ResourceData, meta interface{}) err
d.Set("association_id", association.AssociationId)
d.Set("schedule_expression", association.ScheduleExpression)
d.Set("document_version", association.DocumentVersion)
d.Set("compliance_severity", association.ComplianceSeverity)

if err := d.Set("targets", flattenAwsSsmTargets(association.Targets)); err != nil {
return fmt.Errorf("Error setting targets error: %#v", err)
Expand Down Expand Up @@ -220,6 +237,10 @@ func resourceAwsSsmAssociationUpdate(d *schema.ResourceData, meta interface{}) e
associationInput.OutputLocation = expandSSMAssociationOutputLocation(v.([]interface{}))
}

if v, ok := d.GetOk("compliance_severity"); ok {
associationInput.ComplianceSeverity = aws.String(v.(string))
}

_, err := ssmconn.UpdateAssociation(associationInput)
if err != nil {
return fmt.Errorf("Error updating SSM association: %s", err)
Expand Down
72 changes: 72 additions & 0 deletions aws/resource_aws_ssm_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,41 @@ func TestAccAWSSSMAssociation_withScheduleExpression(t *testing.T) {
})
}

func TestAccAWSSSMAssociation_withComplianceSeverity(t *testing.T) {
assocName := acctest.RandString(10)
rName := acctest.RandString(10)
compSeverity1 := "HIGH"
compSeverity2 := "LOW"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMAssociationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMAssociationBasicConfigWithComplianceSeverity(compSeverity1, rName, assocName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"),
resource.TestCheckResourceAttr(
"aws_ssm_association.foo", "association_name", assocName),
resource.TestCheckResourceAttr(
"aws_ssm_association.foo", "compliance_severity", compSeverity1),
),
},
{
Config: testAccAWSSSMAssociationBasicConfigWithComplianceSeverity(compSeverity2, rName, assocName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMAssociationExists("aws_ssm_association.foo"),
resource.TestCheckResourceAttr(
"aws_ssm_association.foo", "association_name", assocName),
resource.TestCheckResourceAttr(
"aws_ssm_association.foo", "compliance_severity", compSeverity2),
),
},
},
})
}

func testAccCheckAWSSSMAssociationExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -887,3 +922,40 @@ resource "aws_ssm_association" "test" {
}
`, rName, associationName, scheduleExpression)
}

func testAccAWSSSMAssociationBasicConfigWithComplianceSeverity(compSeverity, rName, assocName 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}"
association_name = "%s"
compliance_severity = "%s"
targets {
key = "tag:Name"
values = ["acceptanceTest"]
}
}
`, rName, assocName, compSeverity)
}
1 change: 1 addition & 0 deletions website/docs/r/ssm_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following arguments are supported:
* `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. AWS currently supports a maximum of 5 targets.
* `compliance_severity` - (Optional) The compliance severity for the association. Can be one of the following: `UNSPECIFIED`, `LOW`, `MEDIUM`, `HIGH` or `CRITICAL`

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

Expand Down