This terraform stack creates the network configuration needed for every cloud project.
WARNING: some elements of this stack COST MONEY as long as they are deployed, do not forget to destroy them when not needed. See dedicated chapter in this documentation
You need to deploy the terraform backend.
You do not need anything else for local deployment.
Before deploying this stack via Gitlab CI, you first need to :
- deploy the Docker images for your CI pipelines
- deploy the IAM role which grants Gitlab CI access to your AWS account
- ensure that your repository has access to the CI templates repository
- add to your Gitlab repository CI/CD variables the
ACCOUNT_IDwith the ID of your AWS account
This configuration is composed of multiple elements :
- a VPC
- 3 groups of subnets :
- a public subnet : which cas be accessed from internet (resources created in this subnet by default are affected with a public IP address) and can access internet (with the Internet Gateway created in this subnet)
- a private subnet : which can access internet using the NAT Gateway created in the public subnet but cannot be accessed from the internet (resources in it are not created with a public IP address by default)
- an intra subnet : resources created in this subnet cannot access internet and cannot be accessed from the internet
- an Internet Gateway : resource allowing the public and private subnets to have access to the internet
- a NAT Gateway : resource located in the public subnet allowing the private subnets to have access to the internet
Before deployment, you need to provide some variable values to avoid collision with tenants of this stack in other accounts in the following files:
- the
bucketanddynamodb_tablevalues of the terraform backend in the iac/terraform.tf file. Make them match with the values you used in the terraform backend stack. - the
git_repositoryandproject_namevalue in the iac/terraform.tfvars file. - the
PROJECT_NAMEvariable value and theprojecturi in the .gitlab-ci.yml file
To deploy locally:
cd iac
terraform init -backend-config="bucket=$TERRAFORM_BACKEND_BUCKET" -backend-config="dynamodb_table=$TERRAFORM_BACKEND_DYNAMODB"
terraform workspace new prod
terraform applygit init
git add .
git remote add origin https://my-repo.git
git checkout -b prod
git commit -m "feat: init repo"
git pushYou can destroy the NAT gateway and the Elastic IP when you are not using the Internet Egress capabilities of the private subnets of this network stack.
cd iac
terraform init -backend-config="bucket=$TERRAFORM_BACKEND_BUCKET" -backend-config="dynamodb_table=$TERRAFORM_BACKEND_DYNAMODB"
terraform workspace select prod
terraform destroy -target aws_nat_gateway.instances -target aws_eip.nat_eipsIf you are using Gitlab CI, you can also destroy those resources directly from the pipeline using the destroy-nat-gateway step.
You also have the possibility to schedule the execution of the terraform_apply_schedule which will create all resources and the terraform_destroy_schedule which will destroy only the resources that cast money using Gitlab CI pipeline schedules. It is usefull for example if you have scheduled workload in your account.