Centralize software package distribution in AWS Organizations by using Terraform
Created by Pradip kumar Pandey (AWS), Aarti Rajput (AWS), Chintamani Aphale (AWS), T.V.R.L.Phani Kumar Dadi (AWS), Mayuri Shinde (AWS), and Pratap Kumar Nanda (AWS)
Environment: Production | Technologies: Management & governance; Infrastructure | AWS services: AWS Organizations; AWS Systems Manager |
Summary
Enterprises often maintain multiple AWS accounts that are spread across multiple AWS Regions in order to create a strong isolation barrier between workloads. To stay secure and compliant, their administration teams install agent-based tools such as CrowdStrike
Distributor, a capability of AWS Systems Manager, automates the process of packaging and publishing software to managed Microsoft Windows and Linux instances across the cloud and on-premises servers through a single simplified interface. This pattern demonstrates how you can use Terraform to further simplify the process of managing the installation of software and to run scripts across a large number of instances and member accounts within AWS Organizations with minimal effort.
This solution works for Amazon, Linux, and Windows instances that are managed by Systems Manager.
Prerequisites and limitations
A Distributor package that has the software to be installed
Terraform
version 0.15.0 or later Amazon Elastic Compute Cloud (Amazon EC2) instances that are managed by Systems Manager and have basic permissions to access Amazon Simple Storage Service (Amazon S3
) in the target account A landing zone for your organization that’s set up by using AWS Control Tower
(Optional) Account Factory for Terraform (AFT)
Architecture
Resource details
This pattern uses Account Factory for Terraform (AFT)
Global customization contains Terraform code that will run across all accounts registered with AFT.
Account customizations contains Terraform code that will run in the deployment account.
You can also deploy this solution without using AFT, by running Terraform
The Terraform code deploys the following resources:
AWS Identity and Access Management (IAM) role and policies
SystemsManager-AutomationExecutionRole grants the user permissions to run automations in the target accounts.
SystemsManager-AutomationAdministrationRole grants the user permissions to run automations in multiple accounts and organizational units (OUs).
Compressed files and manifest.json for the package
In Systems Manager, a package includes at least one .zip file of software or installable assets.
The JSON manifest includes pointers to your package code files.
S3 bucket
The distributed package that is shared across the organization is securely stored in an Amazon S3 bucket.
AWS Systems Manager documents (SSM documents)
DistributeSoftwarePackage
contains the logic to distribute the software package to every target instance in the member accounts.AddSoftwarePackageToDistributor
contains the logic to package the installable software assets and add it to Automation, a capability of AWS Systems Manager.
Systems Manager association
A Systems Manager association is used to deploy the solution.
Architecture and workflow
The diagram illustrates the following steps:
To run the solution from a centralized account, you upload your packages or software along with deployment steps to an S3 bucket.
Your customized package becomes available in the Systems Manager console Documents
section, in the Owned by me tab. State Manager, a capability of Systems Manager, creates, schedules, and runs an association for the package across the organization. The association specifies that the software package must be installed and running on a managed node before it can be installed on the target node.
The association instructs Systems Manager to install the package on the target node.
For any subsequent installations or changes, users can run the same association periodically or manually from a single location to perform deployments across accounts.
In member accounts, Automation sends deployment commands to Distributor.
Distributor distributes software packages across instances.
This solution uses the management account within AWS Organizations, but you can also designate an account (delegated administrator) to manage this on behalf of the organization.
Tools
AWS services
Amazon Simple Storage Service (Amazon S3) is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data. This pattern uses Amazon S3 to centralize and securely store the distributed package.
AWS Systems Manager helps you manage your applications and infrastructure running in the AWS Cloud. It simplifies application and resource management, shortens the time to detect and resolve operational problems, and helps you manage your AWS resources securely at scale. This pattern uses the following Systems Manager capabilities:
Distributor helps you package and publish software to Systems Manager managed instances.
Automation simplifies common maintenance, deployment, and remediation tasks for many AWS services.
Documents performs actions on your Systems Manager managed instances across your organization and accounts.
AWS Organizations is an account management service that helps you consolidate multiple AWS accounts into an organization that you create and centrally manage.
Other tools
Terraform
is an infrastructure as code (IaC) tool from HashiCorp that helps you create and manage cloud and on-premises resources.
Code repository
The instructions and code for this pattern are available in the GitHub Centralized package distribution
Best practices
To assign tags to an association, use the AWS Command Line Interface (AWS CLI) or the AWS Tools for PowerShell. Adding tags to an association by using the Systems Manager console isn't supported. For more information, see Tagging Systems Manager resources in the Systems Manager documentation.
To run an association by using a new version of a document shared from another account, set the document version to
default
.To tag only the target node, use one tag key. If you want to target your nodes by using multiple tag keys, use the resource group option.
Epics
Task | Description | Skills required |
---|---|---|
Clone the repository. |
| DevOps engineer |
Update global variables. | Update the following input parameters in the
| DevOps engineer |
Update account variables. | Update the following input parameters in the
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Update input parameters for the State Manager association. | Update the following input parameters in the
| DevOps engineer |
Prepare compressed files and the | This pattern provides sample PowerShell installable files (.msi for Windows and .rpm for Linux) with install and uninstall scripts in the
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Initialize the Terraform configuration. | To deploy the solution automatically with AFT, push the code to AWS CodeCommit:
You can also deploy this solution without using AFT by running a Terraform command from the
| DevOps engineer |
Preview changes. | To preview the changes that Terraform will make to the infrastructre, run the command:
This command evaluates the Terraform configuration to determine the desired state of the resources that have been declared. It also compares the desired state with the actual infrastructure to provision within the workspace. | DevOps engineer |
Apply changes. | Run the following command to implement the changes that you made to the
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Validate the creation of SSM documents. |
You should see the | DevOps engineer |
Validate the successful deployment of automations. |
| DevOps engineer |
Validate that the package deployed to the targeted member account instances. |
| DevOps engineer |
Troubleshooting
Issue | Solution |
---|---|
The State Manager association failed or is stuck in pending status. | See the troubleshooting information |
A scheduled association failed to run. | Your schedule specification might be invalid. State Manager doesn't currently support specifying months in cron expressions for associations. Use cron or rate expressions to confirm the schedule. |
Related resources
Centralized package distribution
(GitHub repository) Use cases and best practices (AWS Systems Manager documentation)