This GitHub repository contains multiple use cases of working with Terraform to provision Amazon EC2 instances. Specific Git branches separate these use cases. To read more about that, click here.
I came across a use cases where I wanted to install and configure Amazon CloudWatch Logs agent on an Amazon EC2 instance for Linux using Terraform aud the user data script. I updated the logic inside the user data script is to:
- Download the Amazon CloudWatch Logs agent installer.
- Install the agent.
- Download the
config.json
from the SSM Parameter store. - Configure and start the CloudWatch Logs agent service.
I automated the resource provisioning process using Terraform, my favorite IaC tool.
I have supporting documentation on my note at: install and configure CloudWatch Logs agent on Amazon EC2 instance for Linux using user data.
I installed terraform
before I worked on this repository. Installation information is available in the install guide.
I used the access_key
and the secret_key
of an IAM user that had permission to create all the resources managed via this terraform
code.
I created a terraform.tfvars
file to store them.
Ensure that the IAM user whose credentials are being used in this configuration has permission to create and manage all the resources that are included in this repository.
Review the code, especially the iamrole.tf
and ec2.tf
file to understand all the concepts associated with creating an IAM role, attaching the role to the AWS managed policy, creating an IAM instance profile with the IAM role and finally attaching the IAM instance profile to the Amazon EC2 instance.
Next, run terraform init
Then run terraform plan
And finally run terraform apply
There are twelve other branches in this repository discussing other use-cases:
This code is released under the Unlincse License. See LICENSE.