Repo for bootstrapping the Cloud Sandbox
This project
- sets up an S3 bucket with a specific bucket policy using Terraform
- creates DynamoDB for state locking. This is always named
"{var.environment}-state-lock
For the CSB it also:
- builds a VPC that tries to conform to the target environment while being independent enough to allow work to be done freely.
- OpenTofu installed on your machine. Terraform also works.
- AWS account with appropriate permissions
-
Clone the repository:
git clone <repository-url> cloud-sandbox-bootstrap cd cloud-sandbox-bootstrap -
Initialize Terraform:
tofu init -
Configure variables: Update the
variables.tffile with your desired bucket name, AWS account ID, and role ARNs or create acloud-sandbox.tfvarsConfigurable items are:
ownerfor who gets to destroy this, if desiredregionfor the AWS region to useenvironmentfor the name of this target environmentbucket_namewhich must often be overridden unless youuse_env_in_bucket_nameuse_env_in_bucket_nameif you want the environment name to be prepended to the state bucket namerole_name_regexis the regex to use to search for the role that should be allowed to write to the state bucket. The system uses the first returned result, so this should return exactly one.subnet_mapis a map(map(string)). The top level is the AZ name to build a subnet. For each subnet, if there is apublickey in the submap, then it should point to the CIDR of a public network. Same for aprivatekey and private network.
These all have reasonable defaults. For elements that are not "production" CSB, the environment should be changed to something else and the bucket name adjusted, if desired.
-
Plan the deployment:
tofu plan -
Apply the configuration:
tofu apply -
Check outputs: After applying, you can see the outputs for the bucket name and ARN.
To remove all resources created by this project:
First, you must change all instances of prevent_destroy = true to prevent_destroy = false in the lifecycle configurations.
Then you can
terraform destroy
Ensure that your AWS credentials are configured properly in your environment for OpenTofu to access your AWS account.