Deploy cloudSwXtch with Terraform on AWS

Prev Next

WHAT TO EXPECT

In this article, you will learn how to deploy a cloudSwXtch instance on AWS using a Terraform script.

Prerequisites:

For this script to work, you will need to have already provisioned your VPC, Subnets, and SSH Keys. You will plug those parameter values into your AWS/terraform/terraform.tfvars file.

Deploying a Terraform Script

  1. Choose what platform you would like to run Terraform on. For this example, the user is on a Linux machine. Download intructions can be found at: terraform.io/downloads

  2. Clone the repository using SSH. Please note: You will need an SSH key set up with GitHub.

    $ git clone git@github.com:swxtchio/cloudSwXtch-support

    Or, alternatively, you can clone with the HTTPS URL: (here on GitHub)

    $ git clone https://github.com/swxtchio/cloudSwXtch-support.git

    Then:

    $ cd cloudSwXtch-support/AWS/terraform
  3. Update the values in the AWS/terraform/terraform.tfvars file to match your existing AWS resources such as: VPC id, Subnet IDs, and SSH Key names.

  4. Run terraform init inside the AWS/terraform/ directory.

  5. For this step you'll need to have authenticated your AWS credentials inside the console. Or you can pass the credentials with environmental variables. One simple way to do this is using an Access Key (AK). If you don't have one, you can generate your AK in Amazon's IAM->Users->(your user), on the Security Credentials tab, Access Keys. Then, you have to export the following:

    $ export AWS_ACCESS_KEY_ID="anaccesskey"
    $ export AWS_SECRET_ACCESS_KEY="asecretkey"
    $ export AWS_REGION="us-west-2"

    Now that Terraform has been initialized and you're authenticated, run this command to evaluate the config and confirm the desired output which will be shown:

    $ terraform plan

This is the result of running terraform plan with 2 cloudSwXtches. The provided terraform example creates a security group for all of the deployed resources: two aws_network_interface for each of the cloudSwXtches and an aws_instance for each cloudSwXtch.

  1. Run the Terraform apply command (followed by “yes” when prompted) to approve the action.

    terraform apply
    yes
  1. Once the resources have been applied successfully, you should see an output similar to this:

You can view the resources created from your AWS portal as confirmation of a successful deployment.