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

[New Resource]: SSM (Systems Manager) - Patch Policy #29549

Closed
thetestlabs opened this issue Feb 21, 2023 · 13 comments · Fixed by #39931
Closed

[New Resource]: SSM (Systems Manager) - Patch Policy #29549

thetestlabs opened this issue Feb 21, 2023 · 13 comments · Fixed by #39931
Assignees
Labels
new-resource Introduces a new resource. service/ssm Issues and PRs that pertain to the ssm service.
Milestone

Comments

@thetestlabs
Copy link

Description

Add support for patch policies. Beginning December 22, 2022, Patch Manager offers a new, recommended method to configure patching for your organization and AWS accounts through the use of patch policies.

https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-policies-about.html

Requested Resource(s) and/or Data Source(s)

aws_ssm_patch_policy

Potential Terraform Configuration

resource "aws_ssm_patch_policy" "example" {
  name        = "example-patch-policy"
  description = "A patch policy with default configuration"

  patch_operation = "scan"         # The options here should be either `scan` or `install`
  patch_baseline  = "default"      # The options here should be `default` or `custom`. `custom` will require either a configuration block or separate resource
  s3_bucket       = "bucket-id"    # S3 Bucket for logging patching operations
  targets         = "organization" # The options here should be `organization`, `custom`, or `current_account`. `custom` will require either a configuration block or separate resource

  scan_schedule {
    # `patch_operation` has options for recommended defaults or a custom scan schedule. This block should configure the custom scan schedule.
    # The first option is to configure a daily schedule
    daily_time = "02:00"
    # The second option is to use a custom CRON expression
    cron_expression = "cron(0 12 * * ? *)"
    # There is also an option to wait to scan targets until first CRON interval.
    wait = true
  }

  rate_control {
    # Rate controls can be expressed as either number of nodes or percentage of nodes
    concurrency     = 10
    error_threshold = 10
  }

  add_iam_policies = true # The options here should be `true` or `false`

}

References

https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-policies-about.html

https://docs.aws.amazon.com/systems-manager/latest/userguide/quick-setup-patch-manager.html

https://aws.amazon.com/blogs/mt/centrally-deploy-patching-operations-across-your-aws-organization-using-systems-manager-quick-setup/

Would you like to implement a fix?

No

@thetestlabs thetestlabs added the needs-triage Waiting for first response or review from a maintainer. label Feb 21, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/ssm Issues and PRs that pertain to the ssm service. label Feb 21, 2023
@justinretzolk justinretzolk added new-resource Introduces a new resource. and removed needs-triage Waiting for first response or review from a maintainer. labels May 3, 2023
@breathingdust breathingdust added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Jul 25, 2023
@HenriBlacksmith
Copy link

Is there a defined schedule to implement this resource?

@jar-b
Copy link
Member

jar-b commented Sep 25, 2023

Hello - In researching this issue we've determined there are currently no public API's for managing SSM patch policies. AWS has confirmed this via a support case, stating at this time the only method for utilizing Quick Setup (and therefore managing patch policies) is the AWS console.

For users interested in this functionality for Terraform, raising a feature request with AWS is the best course of action at this time. Until APIs are available and exposed to the AWS SDK for Go we unfortunately won't be able to take any action.

@jar-b jar-b added upstream Addresses functionality related to the cloud provider. and removed prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Sep 25, 2023
@HenriBlacksmith
Copy link

Hey, in my understanding Quick Setup are pre-configured CloudFormation StackSets.

I assume those can be found through CloudFormation APIs?

@srversent
Copy link

@breathingdust @justinretzolk Do you have updates around delivery timeline of this resource?

@fogers777
Copy link

any update?

@AnItalianMan
Copy link

Hello everyone,

It seems that the API for configuring a Patch Policy through Quick Setup has been released. You can find an example here and the official documentation here.

Please let us know if this will be implemented in a future AWS Terraform provider release.
@breathingdust @justinretzolk

Thanks!

@aristosvo
Copy link
Contributor

Hi @jar-b 👋!

I saw your PR on the client, will you continue with the resources as well? Otherwise I would happily contribute, but your PRs would probably go through a bit faster 🤣

@jar-b
Copy link
Member

jar-b commented Oct 9, 2024

Hey @aristosvo - thanks for checking!

Yes, I meant to assign myself yesterday and missed that step. I'm planning to implement a aws_ssmquicksetup_configuration_manager resource next. Patch policies are one of the configuration types which can be managed with this resource.

@jar-b jar-b self-assigned this Oct 9, 2024
@github-actions github-actions bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Oct 9, 2024
@jar-b jar-b removed the upstream Addresses functionality related to the cloud provider. label Oct 9, 2024
@tommydot
Copy link

Keen for this one too. We are looking into ways to set up a Patch policy for our AWS organization and would love to do it with Terraform if we can.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.74.0 milestone Oct 30, 2024
@jar-b
Copy link
Member

jar-b commented Oct 30, 2024

For those following this issue we'd like to provide some additional context on how to provision patch policies since the final implementation differs a bit from the originally proposed design.

The aws_ssmquicksetup_configuration_manager resource can provision the "Patch Policy" configuration type as follows:

data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
data "aws_region" "current" {}

data "aws_ssm_patch_baselines" "example" {
  default_baselines = true
}

locals {
  # transform the output of the aws_ssm_patch_baselines data source
  # into the format expected by the SelectedPatchBaselines parameter
  selected_patch_baselines = jsonencode({
    for baseline in data.aws_ssm_patch_baselines.example.baseline_identities : baseline.operating_system => {
      "value" : baseline.baseline_id
      "label" : baseline.baseline_name
      "description" : baseline.baseline_description
      "disabled" : !baseline.default_baseline
    }
  })
}

resource "aws_ssmquicksetup_configuration_manager" "example" {
  name = "example"

  configuration_definition {
    local_deployment_administration_role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/AWS-QuickSetup-PatchPolicy-LocalAdministrationRole"
    local_deployment_execution_role_name     = "AWS-QuickSetup-PatchPolicy-LocalExecutionRole"
    type                                     = "AWSQuickSetupType-PatchPolicy"

    parameters = {
      "ConfigurationOptionsPatchOperation" : "Scan",
      "ConfigurationOptionsScanValue" : "cron(0 1 * * ? *)",
      "ConfigurationOptionsScanNextInterval" : "false",
      "PatchBaselineRegion" : data.aws_region.current.name,
      "PatchBaselineUseDefault" : "default",
      "PatchPolicyName" : "example",
      "SelectedPatchBaselines" : local.selected_patch_baselines,
      "OutputLogEnableS3" : "false",
      "RateControlConcurrency" : "10%",
      "RateControlErrorThreshold" : "2%",
      "IsPolicyAttachAllowed" : "false",
      "TargetAccounts" : data.aws_caller_identity.current.account_id,
      "TargetRegions" : data.aws_region.current.name,
      "TargetType" : "*"
    }
  }
}

The administration and execution roles (AWS-QuickSetup-PatchPolicy-LocalAdministrationRole and AWS-QuickSetup-PatchPolicy-LocalExecutionRole, respectively) may already exist in accounts where patch policies were previously configured via the console (AWS will create these automatically if pre-existing customer managed roles are not selected). Alternatively, customer managed roles can be created with equivalent permissions.

The AWS documentation contains a full description of all the keys which can be provided to the parameters argument and their function. In the example above, the patch policy is provisioned only to the current account and region in which the provider is configured.

Lastly, the aws_ssm_patch_baselines data source provides a way to fetch patch baseline IDs in a given account rather than hardcoding copied values from the console or CLI. The transformation in the locals block converts the data source output into the format expected by the SelectedPatchBaselines parameter. This may need to be adjusted for policies which apply to something other than the default baselines in a given account.

@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Oct 31, 2024
Copy link

This functionality has been released in v5.74.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. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-resource Introduces a new resource. service/ssm Issues and PRs that pertain to the ssm service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants