Skip to content

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:

cd ..

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.

ok scaffold infra

Verify that the stack was created:

cd infra/
ls -la

The scaffold command created two new files:

  • for configuring Terraform local variables.
  • 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
ok get-template

Root Domain configuration:

ok get-template root_domain

ECS Cluster configuration:

ok get-template ecs_cluster

RDS Aurora PostgreSQL Serverless configuration:

ok get-template postgres_aurora_serverless

Apply configuration to set up the stack

terraform init
terraform apply

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 applycompletes, a list of name servers will be printed to console.

Output from terraform apply
name_servers = tolist([

These are the name servers for the root domain specified in the module. Because was specified as the root domain, follow this guide Adding a subdomain to to complete the setup.

The domain you defined ( 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:

dig NS +short {your-subdomain}

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}