github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/tools/provisioning/aws/README.md (about)

     1  # Amazon Web Services
     2  
     3  ## Introduction
     4  
     5  This project allows you to get hold of some machine on Amazon Web Services.
     6  You can then use these machines as is or run various Ansible playbooks from `../config_management` to set up Weave Net, Kubernetes, etc.
     7  
     8  ## Setup
     9  
    10  * Log in [weaveworks.signin.aws.amazon.com/console](https://weaveworks.signin.aws.amazon.com/console/) with your account.
    11  
    12  * Go to `Services` > `IAM` > `Users` > Click on your username > `Security credentials` > `Create access key`.
    13    Your access key and secret key will appear on the screen. Set these as environment variables:
    14  
    15  ```
    16  export AWS_ACCESS_KEY_ID=<your access key> 
    17  export AWS_SECRET_ACCESS_KEY=<your secret key>
    18  ```
    19  
    20  * Go to `Services` > `EC2` > Select the availability zone you want to use (see top right corner, e.g. `us-east-1`) > `Import Key Pair`.
    21    Enter your SSH public key and the name for it, and click `Import`.
    22    Set the path to your private key as an environment variable:
    23  
    24  ```
    25  export TF_VAR_aws_public_key_name=<your Amazon Web Services SSH key name>
    26  export TF_VAR_aws_private_key_path="$HOME/.ssh/id_rsa"
    27  ```
    28  
    29  * Set your current IP address as an environment variable:
    30  
    31  ```
    32  export TF_VAR_client_ip=$(curl -s -X GET http://checkip.amazonaws.com/)
    33  ```
    34  
    35    or pass it as a Terraform variable:
    36  
    37  ```
    38  $ terraform <command> -var 'client_ip=$(curl -s -X GET http://checkip.amazonaws.com/)'
    39  ```
    40  
    41  ### Bash aliases
    42  
    43  You can set the above variables temporarily in your current shell, permanently in your `~/.bashrc` file, or define aliases to activate/deactivate them at will with one single command by adding the below to your `~/.bashrc` file:
    44  
    45  ```
    46  function _aws_on() {
    47    export AWS_ACCESS_KEY_ID="<your_access_key_id>"          # Replace with appropriate value.
    48    export AWS_SECRET_ACCESS_KEY="<your_secret_access_key>"  # Replace with appropriate value.
    49    export TF_VAR_aws_public_key_name="<your_ssh_key_name>"  # Replace with appropriate value.
    50    export TF_VAR_aws_private_key_path="$HOME/.ssh/id_rsa"   # Replace with appropriate value.
    51  }
    52  alias _aws_on='_aws_on'
    53  function _aws_off() {
    54    unset AWS_ACCESS_KEY_ID
    55    unset AWS_SECRET_ACCESS_KEY
    56    unset TF_VAR_aws_public_key_name
    57    unset TF_VAR_aws_private_key_path
    58  }
    59  alias _aws_off='_aws_off'
    60  ```
    61  
    62  N.B.: 
    63  
    64  * sourcing `../setup.sh` defines aliases called `aws_on` and `aws_off`, similarly to the above (however, notice no `_` in front of the name, as opposed to the ones above);
    65  * `../setup.sh`'s `aws_on` alias needs the `SECRET_KEY` environment variable to be set in order to decrypt sensitive information.
    66  
    67  ## Usage
    68  
    69  * Create the machine: `terraform apply`
    70  * Show the machine's status: `terraform show`
    71  * Stop and destroy the machine: `terraform destroy`
    72  * SSH into the newly-created machine:
    73  
    74  ```
    75  $ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no `terraform output username`@`terraform output public_ips`
    76  # N.B.: the default username will differ depending on the AMI/OS you installed, e.g. ubuntu for Ubuntu, ec2-user for Red Hat, etc.
    77  ```
    78  
    79  or
    80  
    81  ```
    82  source ../setup.sh
    83  tf_ssh 1  # Or the nth machine, if multiple VMs are provisioned.
    84  ``` 
    85  
    86  ## Resources
    87  
    88  * [https://www.terraform.io/docs/providers/aws/](https://www.terraform.io/docs/providers/aws/)
    89  * [https://www.terraform.io/docs/providers/aws/r/instance.html](https://www.terraform.io/docs/providers/aws/r/instance.html)
    90  * [Terraform variables](https://www.terraform.io/intro/getting-started/variables.html)