This Terraform + Ansible code helps you to create the Golden AMIs for using with your SAP projects. This project creates two Golden AMIs: RedHat Enterprise Linux (RHEL) and Oracle Enterprise Linux (OEL).
- Install several packages using YUM: link
- Install AWS CLI: link
- Install AWS SAP Data Provider: link
- Install EFS Utils: link
- Disable Firewall: link
- Set Clock Source: link
- Set Timezone: link
- Set UUIDD: link
- Disable core dump, KSM, and SELINUX, enable TSX, Configure user limits for SAP, set general limits, set SAP conf and for tmp files, set tuned: link and link
- Make a copy/fork of this repository into your own one
- Make the required changes in the folder
ansible
- Push your code to your own repository
- Take a look at the file
terraform/modules/ec2-image-builder/files/call_ansible_from_git.yaml
- 4.1. On line 24 you'll see it cloning this original repo from main branch. Update it to clone your own repository
- Run the Terraform solution 5.1 If this is not the first version you are running Terraform, add a new entry on the dev.tfvars file under "versions" variable. This way you will create a new build and not discard the previous AMI(s) created
-
1.1. Subscribe to the RHEL AMI:
-
1.2. Launch an instance using your just subscribed image:
-
1.2.5. Click "Launch instance"
-
1.3. Configure your new instance:
- 1.3.1. Now back to the EC2 console, select your new instance and click "Connect".
- 1.3.2. Switch to "SSH client" tab and copy the example string at the botton. It will be something like this:
ssh -i "ec2.pem" ec2-user@ec2-54-166-251-188.compute-1.amazonaws.com
. Fix the path for your keypair (created on item 2.4 line one), paste it in a terminal and hit enter. - 1.3.3. Once you're inside your new instance, run the following command:
sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
(more details available here: https://docs.aws.amazon.com/systems-manager/latest/userguide/agent-install-rhel-8-9.html) - 1.3.4. Run
sudo service amazon-ssm-agent status
to make sure your service is "active" and there are no error logs in the agent.
- 1.3.5. Make sure the overall step 3 is complete by going back into the EC2 console, select your instance, and click Connect. If the tab "Session Manager" doesn't have any error and allows you to click "Connect", leading to a new tab with an SSH session into your instance, it means the SSM agent is correctly installed and you are ready for the automated steps.
IMPORTANT! Make sure to check your SSM installation using step 3.5. If the SSM Agent installation is not correctly done, the automated steps with EC2 Image Builder will not work!
-
1.4. Create your BASE AMI for EC2 Image Builder to use:
- 1.4.1 - Now back on the EC2 console, select your instance, click "Actions", then "Image and templates", then "Create image".
- 1.4.2 - Give it the name "rhel-base" and click "Create image".
- 1.4.3 - Go to "AMIs" on the menu on the left, find your new AMI and wait for it to be on Status "Available".
- 1.4.4 - Copy the AMI ID and save it somewhere safe
-
1.5. Clean up the resources:
- 1.5.1 - Delete the rhel-base instance used for capturing the AMI
- 1.5.2 - Delete the security group created for SSHing into the instance (named launch-wizard-X)
- 2.1. Find your base AMI in this blog post from Oracle: https://forums.oracle.com/ords/apexds/post/launch-an-oracle-linux-instance-in-aws-9462
- 2.2. Once you find your AMI, on the list click "Launch instance from AMI"
- 2.3. Use the same instructions on step 1.2.4 above up until the end
- 2.4. After you are done creating your new AMI with the SSM Agent installed in it, for creating the new Parameter in Parameter Store (step 1.4.6 above), use the name
/dev/ec2/amis/oel/base
- 3.1. Create an S3 bucket to save your Terraform states and save its name. How to create the bucket here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html
- 3.2. Update the file
run_terraform_init.sh
in this repo changing the value for the variable "BUCKET_NAME" with your new bucket - 3.3. IMPORTANT: for productive environments, the run_terraform_init.sh should be updated to include a Dynamo DB table too. This prevents errors in the Terraform State file caused by multiple people trying to update it at the same time. More here: https://developer.hashicorp.com/terraform/language/settings/backends/s3
- 3.4 - In a console, cd into the terraform folder and run
./run_terraform_init.sh
- 3.5 - Rename the file dev.tfvars.template into dev.tfvars and replace the following values:
Variable | Comment | Sample value |
---|---|---|
kms_key_arn | The KMS ARN you want to use. More on how to create keys: https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html | KMS ARN |
vpc_id | The VPC ID to deploy this solution into | vpc-136fg512a80503b82 |
subnet_id | The Subnet ID to deploy this solution into | subnet-9efcd1og8f764b86f |
base_ami (RHEL) | First base_ami is for RHEL | ami-01453fg90e53509e3 |
base_ami (OEL) | Second base_ami is for OEL | ami-01453fg90e53509e3 |
- 3.6 - Run
./run_terraform_plan.sh
and check the resources you are about to create - 3.7 - Run
./run_terraform_apply.sh
- 3.8 - Results: