This repository contains the Terraform code to provision an Amazon ElastiCache for Memcached and all the supporting infrastructure components like Amazon VPC, subnets, and security group using Terraform. It also contains the additional code to access the ElastiCache cluster from an Amazon EC2 instance.
I discussed both the concept in detail in my notes at -create Amazon ElastiCache for Memcached using Terraform and GitHub Actions and access Amazon ElastiCache for Memcached from an Amazon EC2 instance using Python.
I used Bridgecrew Checkov to scan the Terraform code for security vulnerabilities. Here is a link if you are interested in adding code scanning capabilities to your GitHub Actions pipeline -automate-terraform-configuration-scan-with-checkov-and-github-actions.
I also used Infracost to generate a cost estimate of building the architecture. If you want to learn more about adding Infracost estimates to your repository, head over to this note -estimate AWS Cloud resource cost with Infracost, Terraform, and GitHub Actions.
Lastly, I also automated the process of provisioning the resources using GitHub Actions pipeline and I discussed that in detail at -CI-CD with Terraform and GitHub Actions to deploy to AWS.
For this code to function without errors, I created an OpenID connect identity provider in Amazon Identity and Access Management that has a trust relationship with this GitHub repository. You can read about it here to get a detailed explanation with steps.
I stored the ARN of the IAM Role as a GitHub secret which is referred in the terraform.yml
file.
Since I used Infracost in this repository, I stored the INFRACOST_API_KEY
as a repository secret. It is referenced in the terraform.yml
GitHub actions workflow file.
As part of the Infracost integration, I also created a INFRACOST_API_KEY
and stored that as a GitHub Actions secret. I also managed the cost estimate process using a GitHub Actions variable INFRACOST_SCAN_TYPE
where the value is either hcl_code
or tf_plan
, depending on the type of scan desired.
Name | Version |
---|---|
aws | 5.61.0 |
Name | Version |
---|---|
aws | 5.61.0 |
Name | Source | Version |
---|---|---|
vpc | github.com/kunduso/terraform-aws-vpc | v1.0.1 |
Name | Type |
---|---|
aws_elasticache_cluster.cache_cluster | resource |
aws_elasticache_subnet_group.elasticache_subnet | resource |
aws_iam_instance_profile.ec2_profile | resource |
aws_iam_policy.ssm_parameter_policy | resource |
aws_iam_role.ec2_role | resource |
aws_iam_role_policy_attachment.custom | resource |
aws_iam_role_policy_attachment.ssm_policy_attachement | resource |
aws_instance.read_instance | resource |
aws_instance.write_instance | resource |
aws_kms_alias.encryption_secret | resource |
aws_kms_key.encrypt_ssm | resource |
aws_kms_key_policy.encrypt_ssm_policy | resource |
aws_security_group.custom_sg | resource |
aws_security_group.instance_sg | resource |
aws_security_group_rule.egress_custom_sg | resource |
aws_security_group_rule.egress_instance_sg | resource |
aws_security_group_rule.ingress_custom_sg | resource |
aws_ssm_parameter.elasticache_ep | resource |
aws_ami.ec2_ami | data source |
aws_caller_identity.current | data source |
aws_iam_policy_document.encrypt_ssm_policy | data source |
aws_region.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
access_key | The access_key that belongs to the IAM user | string |
"" |
no |
availability_zone | The availability zones for teh public subnets. | list(any) |
[ |
no |
name | The name of the application. | string |
"app-10" |
no |
region | Infrastructure region | string |
"us-east-2" |
no |
secret_key | The secret_key that belongs to the IAM user | string |
"" |
no |
subnet_cidr_private | The CIDR blocks for the private subnets. | list(any) |
[ |
no |
subnet_cidr_public | The CIDR blocks for the public subnets. | list(any) |
[ |
no |
vpc_cidr | The CIDR of the VPC. | string |
"12.25.15.0/25" |
no |
No outputs.
Ensure that the policy attached to the IAM role 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 including the terraform.yml
to understand the steps in the GitHub Actions pipeline. Also review the terraform code to understand all the concepts associated with creating an AWS VPC, subnets, internet gateway, route table, and route table association.
If you want to check the pipeline logs, click on the Build Badge (terrform-infra-provisioning) above the image in this ReadMe.
If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request. Contributions are always welcome!
This code is released under the Unlincse License. See LICENSE.