Follow instructions in the READMEs.
- make local-cdktf-install
- make local-cdktf-vpc-deploy
- make local-cdktf-deploy
- make local-cdktf-test
- make local-cdktf-invoke
- make local-cdktf-clean
AWS targets
- make sbx-cdktf-install
- make sbx-cdktf-vpc-deploy
- make sbx-cdktf-deploy
- make sbx-cdktf-jump-deploy (deploy jumphost in private VPC subnet)
- make sbx-cdktf-jump-destroy
- make sbx-cdktf-destroy
- make sbx-cdktf-vpc-destroy
You need to do this initially, and if you manually add packages to iac/terraform/cdk/package.json
make local-cdktf-installThis will deploy a VPC using the configuration in devops-tooling/accounts.
make local-cdktf-vpc-deployNote: the above command will fail if it has been applied on a previous instance of Localstack unless make local-cdktf-clean is run before.
This will deploy the resources.
make local-cdktf-deployThe Lambda is setup for hot reloading in this project on LocalStack by default. After everything is deployed by following one of complete IaC deployments above, you can work with the Lambda in hot-reload mode. See LocalStack Hot Reloading
Now, your DevX looks like a rapid TDD cycle. There's a test in auto_tests/test_apigw_name.py.
Run watchman to do a build whenever code changes in the Lambda.
Change the Lambda in ./src/lambda-hello-name/src. It'll recompile and redeploy on the fly. Then rerun the tests.
make watch-lambdaThen run the test(s)
make local-cdktf-testAfter you run the tests once, you don't have to save the IaC output again, so you can just run this and save some time.
make testmake local-cdktf-invokemake local-cdktf-cleanWe use the same IaC pipelines to deploy to AWS! This is a very important point that LocalStack enables teams to test their IaC pipelines locally before ever deploying them to a live AWS environment.
However you set your credentials in your terminal, do it now.
This project stores Terraform state in an AWS S3 bucket in the target account. Create an S3 bucket in your target account to hold the Terraform state
aws s3 mb s3://<name of your bucket>-<region where bucket is> --region <region where your bucket is>
# enable versioning in case of state corruption
aws s3api put-bucket-versioning --bucket <your full bucket name> --versioning-configuration Status=EnabledCreate a file called sandboxenv.makefile at the root of this project.
sbx%: export TERRAFORM_STATE_BUCKET=<your bucket name. ie my-happy-bucket-us-east-1>
sbx%: export PULUMI_BACKEND_URL=s3://$(TERRAFORM_STATE_BUCKET)- In the file
.env-gdc-localthat you created in the Setup instructions in the main README, add an entry forSBX_ACCOUNT_CONFIGthat points to a file in the./devops-tooling/accountsdirectory named something likemy-sb-yourname.json. And add this entry to.env-gdc-local. Fill in the appropriate values that have placeholders in thedevops-tooling/accounts/my-sb.jsonfile.
export SBX_ACCOUNT_CONFIG=devops-tooling/accounts/my-sb-yourname.jsonConfigure a Sandbox VPC in my-sb-yourname.json. Change the CIDR block to your preferences.
{
"accountNum": "<YOUR AWS ACCOUNT ID HERE>",
"accountName": "mysb",
"description": "My Sandbox VPC",
"regions": [
{
"region": "us-east-1",
"accountType": "sandbox",
"vpcName": "mysb",
"vpcConfig": {
"cidrBlock": "10.42.0.0/16",
"numberOfAvailabilityZones": 4,
"subnetCidrMask": 20
}
}
]
}
This will deploy a VPC using the configuration in devops-tooling/accounts.
make sbx-cdktf-vpc-deployThis will deploy the resources.
make sbx-cdktf-deploymake sbx-cdktf-jump-deployThis will output the EC2 ID. You can connect to this EC2 instance by
- Install the AWS Systems Manager Plugin [https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html]
- Clone the GDC to get the
ssm-ssh.shscript. [https://gitlab.com/probello/generic-dev-container] - Use this script to login to the EC2 instance like this [https://gitlab.com/probello/generic-dev-container/-/blob/main/root/bin/aws/ssm-ssh.sh?ref_type=heads]
# Get AWS credentials
ssm-ssh.sh <ec2 instance id>make sbx-cdktf-invokeNow you can invoke it again and view the new output.
make sbx-cdktf-destroymake sbx-cdktf-vpc-destroy