Create a new stack for shared infrastructure
This guide is outdated
We do not recommend using a shared stack like the one created in this guide any more. We recommend using micro stacks.
If you are setting up something new, please contact team Kjøremiljø first so we can do this together For more up to date information about how to set up your infrastructure you can take sneak peek at our reference app pirates-iac.
This guide can still be used for trouble shooting purposes for teams that have not yet taken the micro stack structure in use.
This stack will contain all the shared infrastructure that is needed the application stack we will create later. This includes VPC, Subnets, NAT gateways, ECS Cluster, Postgres database etc.
Prepare shared stack
Creating stacks
To create a new stack we use the ok scaffold
command. This will create a new directory with the name provided as the
argument to ok scaffold
and generate the necessary files for Terraform to create the stack.
Navigate to the root of the environment directory:
Run the ok scaffold
command to create a new stack.
Naming stacks
You could name the stack anything you want, but we recommend that you use infra
for the shared infrastructure
resources.
Verify that the stack was created:
The scaffold command created two new files:
config.tf
for configuring Terraform local variables.common.tf
with basic Terraform setup (the AWS provider, the S3 backend we set up above and some shared configuration variables used by the Golden Path modules).
We can now proceed to add the configuration we want to use in this stack.
Add modules to shared stack
Replacing variables
For each of the templates you're about to download, you will need to open each one of the files and replace some variables with your own values. The variables that you need to replace are documented in each of the files.
Make sure you are in the infra
directory.
VPC configuration:
ok get-template vpc
ok get-template _variables_vpc.tf
ok get-template _config_vpc.auto.tfvars.json
Root Domain configuration:
ECS Cluster configuration:
RDS Aurora PostgreSQL Serverless configuration:
Apply configuration to set up the stack
Coffee break
This step might take anywhere from 10 to 15 minutes to complete, and once complete it will display some important output that you will need to use in the next step.
Review output from stack creation
Adding DNS Name Servers
Onceterraform apply
completes, a list of name servers will be printed to console.
name_servers = tolist([
"ns-123.awsdns-44.org",
"ns-321.awsdns-29.co.uk",
"ns-213.awsdns-35.com",
"ns-231.awsdns-18.net",
])
These are the name servers for the root domain specified in the root_domain.tf
module. Because oslo.systems
was specified as the root domain, follow this guide Adding a subdomain to oslo.systems
to complete the setup.
The domain you defined (my-team-dev.oslo.systems
) should now resolve to the application or applications you deploy in the next step of the guide.
To verify that the subdomain is properly registered with a name server:
This should give you a list of name servers corresponding to the list of name servers printed after the last terraform apply
above.
If you don't have dig
installed, use this DNS lookup tool to check {your-subdomain}.oslo.systems
.