Building AWS infra with terraform

To set up the infrastructure, you need to clone the tokamak-thanos-stack repository to your local machine.

Visit the link below to clone the repository:

The tokamak-thanos-stack repository is structured as follows:

  • charts: Helm charts for deploying the Thanos chain.

  • terraform: Terraform code is used to configure the AWS infrastructure to run the Thanos chain.

In this guide, we will use the Terraform code to set up the infrastructure that forms the foundation of the Thanos chain.

Configure env

Before deploying the infrastructure with Terraform, you need to set up environment variables. we manage the environment variables by creating a .envrc file.

  1. Go to terraform directory

    cd terraform
  2. Copy .envrc.example file to .envrc.

    cp .envrc.example .envrc
  3. Please fill in the values for the items listed below in the copied file.

    • TF_VAR_thanos_stack_name: Name

    • TF_VAR_aws_region: The AWS region to use.

    • TF_VAR_sequencer_key: The Sequencer Private key.

    • TF_VAR_batcher_key: The Batcher Private key.

    • TF_VAR_proposer_key: The Proposer Private key.

    • TF_VAR_challenger_key: The Challenger Private key.

    • TF_VAR_eks_cluster_admins: Your IAM user ARN.

    • TF_VAR_stack_deployments_path: The path to the file containing the L1 contract address. You can find it here.

    • TF_VAR_stack_l1_rpc_url: The L1 RPC endpoint.

    • TF_VAR_stack_l1_rpc_provider: The L1 RPC Provider.

    • TF_VAR_stack_l1_beacon_url: The beacon RPC endpoint

Note to env configure

  1. Variables with default values do not need to be modified.

  2. You can ignore TF_VAR_backend_bucket_name for now, as it will be filled in after configuring the Terraform backend.

  3. The ARN of the IAM user can be found in the EC2 console under Users > User name > Summary tab.

When you've filled it all in, it should look like this:

  1. Save and apply the environment variables using the following command.

Make backend

Before provisioning AWS resources with Terraform, you need to set up a backend storage to store the state information. The backend storage will use AWS S3.

  1. Go to backend directory

  2. Command terraform init

  3. Command terraform plan to verify if the backend creation is set up correctly.

  4. Command terraform apply to create the backend.

    <aside> 💡

    The error can be ignored because it occurred after the backend was created and the TF_VAR_backend_bucket_name value in the environment file was automatically filled in.

    </aside>

  5. Go back terraform directory and apply the environment variables

Set up Thanos stack infrastructure

In this phase, we will set up the infrastructure needed to run the apps required for operating the Thanos chain, and to do so, we will create the following resources:

  • vpc: VPC is a networking service provided by AWS.

  • secretsmanager: The Secrets Manager stores the private keys used by operator nodes.

  • chain-config: Storage for genesis file and rollup file. used AWS S3

  • EFS: EFS is a cloud-based file system service. It is used for the file system storage of Thanos stack services.

  • EKS: EKS is a managed Kubernetes service. It is used to deploy and manage applications in the Thanos stack.

  • kubernetes: This module is for deploying controllers to use AWS services in Kubernetes. It deploys controllers for load balancers, coredns, and secrets.

Bring genesis and rollup files

Before building the infrastructure, make sure to have the genesis and rollup files created during step 2.

  1. Go to thanos-stack directory

  2. Copy generate and rollup files to config-files directory.

Building infrastructure

  1. Go to thanos-stack directory

  2. Command terraform init

  3. Command terraform plan to verify if the thanos-stack infra creation is set up correctly.

  4. Command terraform apply to create the thanos-stack infra. The process will take around 15 to 20 minutes to complete.

  5. Once the infrastructure setup is complete, you’ll see that the thanos-stack-values.yaml file has been created. This file will be used in the next step to deploy the Thanos chain.

  6. To interact with EKS, register the EKS kubeconfig with kubectl.

With the infrastructure setup complete, proceed to the next phase

Last updated