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_patch_group cannot handle multiple baselines of differing OS in a single patch group #9603

Closed
jdheyburn opened this issue Aug 2, 2019 · 10 comments · Fixed by #15213
Labels
bug Addresses a defect in current functionality. service/ssm Issues and PRs that pertain to the ssm service.
Milestone

Comments

@jdheyburn
Copy link
Contributor

jdheyburn commented Aug 2, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

$ terraform -v
Terraform v0.12.6
+ provider.aws v2.22.0

Affected Resource(s)

  • aws_ssm_patch_group

Terraform Configuration Files

resource "aws_ssm_patch_baseline" "centos" {
  name             = "centos-patch-baseline"
  description      = "Patch baseline for centos"
  operating_system = "CENTOS"

  approval_rule {
    approve_after_days = "0"

    patch_filter {
      key    = "CLASSIFICATION"
      values = ["*"]
    }
  }
}

resource "aws_ssm_patch_baseline" "amazon_linux_2" {
  name             = "amazon_linux_2-patch-baseline"
  description      = "Patch baseline for amazon_linux_2"
  operating_system = "AMAZON_LINUX_2"

  approval_rule {
    approve_after_days = "0"

    patch_filter {
      key    = "CLASSIFICATION"
      values = ["*"]
    }
  }
}

resource "aws_ssm_patch_baseline" "amazon_linux" {
  name             = "amazon_linux-patch-baseline"
  description      = "Patch baseline for amazon_linux"
  operating_system = "AMAZON_LINUX"

  approval_rule {
    approve_after_days = "0"

    patch_filter {
      key    = "CLASSIFICATION"
      values = ["*"]
    }
  }
}

resource "aws_ssm_patch_group" "centos" {
    patch_group = "patch_group"
    baseline_id = "${aws_ssm_patch_baseline.centos.id}"
}

resource "aws_ssm_patch_group" "amazon_linux_2" {
    patch_group = "patch_group"
    baseline_id = "${aws_ssm_patch_baseline.amazon_linux_2.id}"
}

resource "aws_ssm_patch_group" "amazon_linux" {
    patch_group = "patch_group"
    baseline_id = "${aws_ssm_patch_baseline.amazon_linux.id}"
}

Debug Output

Apply output: https://gist.github.com/jdheyburn/e8298fa7b182f39948c98b34909fe2eb

Panic Output

N/A

Expected Behavior

  • Patch group should be unaltered, keeping all baselines

Actual Behavior

  • A baseline is removed from patch group

Output of the apply

Terraform will perform the following actions:

  # aws_ssm_patch_group.amazon_linux must be replaced
-/+ resource "aws_ssm_patch_group" "amazon_linux" {
      ~ baseline_id = "pb-01ad30a5a012192ed" -> "pb-0a38d8d0f7b2d56ce" # forces replacement
      ~ id          = "patch_group" -> (known after apply)
        patch_group = "patch_group"
    }

  # aws_ssm_patch_group.amazon_linux_2 must be replaced
-/+ resource "aws_ssm_patch_group" "amazon_linux_2" {
      ~ baseline_id = "pb-01ad30a5a012192ed" -> "pb-00fb43e57d24e1b2c" # forces replacement
      ~ id          = "patch_group" -> (known after apply)
        patch_group = "patch_group"
    }

Plan: 2 to add, 0 to change, 2 to destroy.

Note the following baseline IDs for referencing the above plan outpuit:
amazon_linux_2 = pb-00fb43e57d24e1b2c
centos = pb-01ad30a5a012192ed
amazon_linux = pb-0a38d8d0f7b2d56ce

Steps to Reproduce

With the above HCL:

  1. Build out the scenario of 3 baselines added to 1 patch group: terraform apply
  2. View the results on the console, there are 3 baselines to the new patch group
  3. With no changes to the code, apply again: terraform apply
  4. See how the plan wants to alter the baseline
  5. After apply, view patch group in console, it removes a baseline
  6. This will then cycle forever

Important Factoids

N/A

References

Patch groups can be assigned many baselines, but only one baseline per OS - this is the how it functions in AWS console. Terraform here is assuming that a patch group can only have one baseline - or that it is only reading the first patch group entry retrieved from describe-patch-groups and then making changes from there.

@ghost ghost added the service/ssm Issues and PRs that pertain to the ssm service. label Aug 2, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Aug 2, 2019
@XDanny322
Copy link

XDanny322 commented Jan 15, 2020

FWIW - Just reproduced this issue on version 0.12.18, on provider:

./plugins/darwin_amd64/terraform-provider-null_v2.1.2_x4
./plugins/darwin_amd64/terraform-provider-archive_v1.3.0_x4
./plugins/darwin_amd64/terraform-provider-aws_v2.44.0_x4

@jdheyburn
Copy link
Contributor Author

Hope to take a look at this over the next coming weeks.

@andycohen
Copy link

Your comments don't follow with AWS own documentation:

https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-patch-patchgroups.html

Note
A patch group can only be registered with one patch baseline.

Therefore the Terraform behaviour is correct, no?

@jdheyburn
Copy link
Contributor Author

Correct, however a patch baseline can have multiple patch groups. This is what Terraform fails to pick up. On the Modify Patch Groups page in AWS Console:

Patch groups
You can create up to 25 tag values to define patch groups for this patch baseline. Tag keys are > automatically named Patch Group. Learn more

My original example should ideally have separate patch group names to highlight this.

@rentiak
Copy link

rentiak commented May 11, 2020

Your comments don't follow with AWS own documentation:

https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-patch-patchgroups.html

Note
A patch group can only be registered with one patch baseline.

Therefore the Terraform behaviour is correct, no?

This is actually not correct as the docs are somewhat misleading. You can have a single patch group registered with multiple patch baselines if they are for different operating systems. That line should really read "A patch group can only be registered with one patch baseline per operating system"

See below as an example where I've created an Internal Systems patch baseline for each OS (Windows, Amzn1 and Amzn2) and associated them with a single patch group:
Screen Shot 2020-05-11 at 12 24 02 PM

@eerkunt
Copy link

eerkunt commented May 15, 2020

We are having the same problem. Even though it is written as above in the documentation, even aws-cli allows to register multiple patch baseline to one group. IMHO, the problem looks like, the id that is used as a resource reference within the terraform state is set to baseline_id which is making any sequential plan/apply operation confused.

@varun1231
Copy link

varun1231 commented May 15, 2020

Terraform has aws_ssm_patch_group resource while there is no CreatePatchGroup in the AWS API. it is basically registering a patch baseline with a patch group. the workaround is probably using a null resource to run the register-patch-baseline-for-patch-group cli to do this task with a sha trigger based on the baseline resource and patch group input and obviously run deregister-patch-baseline-for-patch-group for a destroy operation to keep it clean - thanks @eerkunt for this steer.

@meons
Copy link

meons commented Aug 31, 2020

👍

@anGie44 anGie44 added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 17, 2021
@anGie44 anGie44 added this to the v3.33.0 milestone Mar 17, 2021
@ghost
Copy link

ghost commented Mar 18, 2021

This has been released in version 3.33.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Apr 16, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ssm Issues and PRs that pertain to the ssm service.
Projects
None yet
8 participants