Skip to content

Commit

Permalink
Merge pull request #1260 from stack72/f-aws-ssm-patch-baseline-1257
Browse files Browse the repository at this point in the history
resource/aws_ssm_patch_baseline: Update support for Operating System
  • Loading branch information
grubernaut committed Jul 28, 2017
2 parents 1ad5c2e + 38dfc58 commit 126a648
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
21 changes: 21 additions & 0 deletions aws/resource_aws_ssm_patch_baseline.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 resourceAwsSsmPatchBaseline() *schema.Resource {
Expand Down Expand Up @@ -96,6 +97,22 @@ func resourceAwsSsmPatchBaseline() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"operating_system": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "WINDOWS",
ValidateFunc: validation.StringInSlice([]string{"WINDOWS", "AMAZON_LINUX", "UBUNTU", "REDHAT_ENTERPRISE_LINUX"}, false),
},

"approved_patches_compliance_level": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "UNSPECIFIED",
ValidateFunc: validation.StringInSlice([]string{"CRITICAL", "HIGH", "MEDIUM", "LOW", "INFORMATIONAL", "UNSPECIFIED"}, false),
},
},
}
}
Expand All @@ -105,6 +122,8 @@ func resourceAwsSsmPatchBaselineCreate(d *schema.ResourceData, meta interface{})

params := &ssm.CreatePatchBaselineInput{
Name: aws.String(d.Get("name").(string)),
ApprovedPatchesComplianceLevel: aws.String(d.Get("approved_patches_compliance_level").(string)),
OperatingSystem: aws.String(d.Get("operating_system").(string)),
}

if v, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -150,6 +169,8 @@ func resourceAwsSsmPatchBaselineRead(d *schema.ResourceData, meta interface{}) e

d.Set("name", resp.Name)
d.Set("description", resp.Description)
d.Set("operating_system", resp.OperatingSystem)
d.Set("approved_patches_compliance_level", resp.ApprovedPatchesComplianceLevel)
d.Set("approved_patches", flattenStringList(resp.ApprovedPatches))
d.Set("rejected_patches", flattenStringList(resp.RejectedPatches))

Expand Down
50 changes: 50 additions & 0 deletions aws/resource_aws_ssm_patch_baseline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ func TestAccAWSSSMPatchBaseline_basic(t *testing.T) {
})
}

func TestAccAWSSSMPatchBaselineWithOperatingSystem(t *testing.T) {
name := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMPatchBaselineConfigWithOperatingSystem(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMPatchBaselineExists("aws_ssm_patch_baseline.foo"),
resource.TestCheckResourceAttr(
"aws_ssm_patch_baseline.foo", "approval_rule.#", "1"),
resource.TestCheckResourceAttr(
"aws_ssm_patch_baseline.foo", "approval_rule.0.approve_after_days", "7"),
resource.TestCheckResourceAttr(
"aws_ssm_patch_baseline.foo", "approval_rule.0.patch_filter.#", "2"),
resource.TestCheckResourceAttr(
"aws_ssm_patch_baseline.foo", "operating_system", "AMAZON_LINUX"),
),
},
},
})
}

func testAccCheckAWSSSMPatchBaselineExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -135,3 +160,28 @@ resource "aws_ssm_patch_baseline" "foo" {
`, rName)
}

func testAccAWSSSMPatchBaselineConfigWithOperatingSystem(rName string) string {
return fmt.Sprintf(`
resource "aws_ssm_patch_baseline" "foo" {
name = "patch-baseline-%s"
operating_system = "AMAZON_LINUX"
description = "Baseline containing all updates approved for production systems"
approval_rule {
approve_after_days = 7
patch_filter {
key = "PRODUCT"
values = ["AmazonLinux2016.03","AmazonLinux2016.09","AmazonLinux2017.03","AmazonLinux2017.09"]
}
patch_filter {
key = "SEVERITY"
values = ["Critical","Important"]
}
}
}
`, rName)
}
2 changes: 2 additions & 0 deletions website/docs/r/ssm_patch_baseline.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ The following arguments are supported:

* `name` - (Required) The name of the patch baseline.
* `description` - (Optional) The description of the patch baseline.
* `operating_system` - (Optional) Defines the operating system the patch baseline applies to. Supported operating systems include `WINDOWS`, `AMAZON_LINUX`, `UBUNTU` and `REDHAT_ENTERPRISE_LINUX`. The Default value is `WINDOWS`.
* `approved_patches_compliance_level` - (Optional) Defines the compliance level for approved patches. This means that if an approved patch is reported as missing, this is the severity of the compliance violation. Valid compliance severity levels include the following: `CRITICAL`, `HIGH`, `MEDIUM`, `LOW`, `INFORMATIONAL`, `UNSPECIFIED`. The default value is `UNSPECIFIED`.
* `approved_patches` - (Optional) A list of explicitly approved patches for the baseline.
* `rejected_patches` - (Optional) A list of rejected patches.
* `global_filter` - (Optional) A set of global filters used to exclude patches from the baseline. Up to 4 global filters can be specified using Key/Value pairs. Valid Keys are `PRODUCT | CLASSIFICATION | MSRC_SEVERITY | PATCH_ID`.
Expand Down

0 comments on commit 126a648

Please sign in to comment.