- AWS CLI installed and configured
- Terraform installed
- An AWS account with necessary permissions, including:
iam:PassRolepermission for the CodeBuild, CodeDeploy, and CodePipeline service roles- Permissions to create and manage resources in S3, CodeCommit, CodeBuild, CodeDeploy, CodePipeline, EC2, and CloudWatch
-
Clone this repository:
git clone <repository-url> cd <repository-directory> -
Initialize Terraform:
terraform init -
Review and modify the
variables.tffile to set your desired values. -
Plan the Terraform execution:
terraform plan -
Apply the Terraform configuration:
terraform apply -
After successful application, Terraform will output important information like the CodeCommit repository URL. Make note of these outputs.
-
Push your application code to the newly created CodeCommit repository.
-
The CI/CD pipeline will automatically trigger on new commits to the main branch.
buildspec.yml: This file should be in your source code repository and contain the build instructions for CodeBuild.appspec.yml: This file should be in your source code repository and contain the deployment instructions for CodeDeploy.
To avoid incurring future charges, remember to destroy the resources when you're done:
-
(Optional) Set the ARNs for existing IAM roles: If you have existing IAM roles for CodeBuild, CodeDeploy, and CodePipeline, you can set them in the
variables.tffile or pass them as variables when applying the Terraform configuration:terraform apply \ -var="existing_codebuild_role_arn=arn:aws:iam::ACCOUNT_ID:role/existing-codebuild-role" \ -var="existing_codedeploy_role_arn=arn:aws:iam::ACCOUNT_ID:role/existing-codedeploy-role" \ -var="existing_codepipeline_role_arn=arn:aws:iam::ACCOUNT_ID:role/existing-codepipeline-role"Replace
ACCOUNT_IDwith your AWS account ID and ensure the role names are correct. If you don't provide these ARNs, new roles will be created automatically.
...
-
(Optional) Override existing IAM role ARNs: The configuration includes default ARNs for existing IAM roles. If you need to use different roles, you can override them by setting the following variables:
terraform apply \ -var="existing_codebuild_role_arn=arn:aws:iam::ACCOUNT_ID:role/your-codebuild-role" \ -var="existing_codedeploy_role_arn=arn:aws:iam::ACCOUNT_ID:role/your-codedeploy-role" \ -var="existing_codepipeline_role_arn=arn:aws:iam::ACCOUNT_ID:role/your-codepipeline-role"Replace
ACCOUNT_IDwith your AWS account ID and adjust the role names as needed.