This little repo illustrates how to build a CodeBuild
project with terraform
and run terraform inside of this project to build infrastructure from another repo. This other repo builds a simple ec2
instance.
Before running this terraform template add the following terraform config file.
Create a settings file terraform.auto.tfvars
with the following:
echo <<< EOL
aws_access_key = "XXXXXXXXXXXXXXXXXXXX"
aws_secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
aws_region = "us-east-1"
public_key = "ssh-rsa AAAAB3NzaC1yc....9wrf+M7Q== [email protected]"
vpc_id = "vpc-00000000x00x0xxx0"
terraform_version = "0.9.9"
s3_bucket = "your-s3-bucket-terraform-state"
debug = "true"
EOL >> terraform.auto.tfvars;
After you're done creating the above file and adding your aws access key
, secret
and your ssh public key
, run the following:
terraform init
terraform plan
echo yes | terraform apply
To remove what you built run:
echo yes | terraform destroy
The above terraform apply
statement will create your CodeBuild project. After creating your project in AWS you should find your CodeBase project here:
https://console.aws.amazon.com/codesuite/codebuild/projects?region=us-east-1
(Change your region in this URL to what you set your aws_region
variable in your tfvars
file to.)
Your project in CodeBuild will look something like the image below:
Select your project and click Start Build
:
Select Advanced build overrides
:
Unfold Additional configuration
and edit any of the environment variables. Set the DESTROY
variable to true
if you would like to run a build cycle that destroys your infrastructure.
Press Start Build
.
You're done and have fun!