|
1 | | -# terraform-demo-aws |
2 | | -Terraform Demo using AWS provider |
| 1 | +# Terraform Demo using AWS provider |
| 2 | + |
| 3 | +## Create IAM User |
| 4 | +1. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/ |
| 5 | +2. In the navigation pane, choose Users and then choose Add user |
| 6 | +3. Type the user name for the new user |
| 7 | +4. Select the type of access: `Programmatic access` |
| 8 | +5. Choose `Next`: Permissions |
| 9 | +6. On the Set permissions page, choose `Attach existing policies to user directly` and select `IAMFullAccess` |
| 10 | +7. Choose Next: Review to see all of the choices you made up to this point |
| 11 | +8. Choose `Create` |
| 12 | + |
| 13 | +## Get Access Key ID and Secret Access Key for IAM User |
| 14 | +1. Open the IAM console |
| 15 | +2. In the navigation pane of the console, choose Users |
| 16 | +3. Choose your IAM user name (not the check box) |
| 17 | +4. Choose the Security credentials tab and then choose Create access key |
| 18 | +5. To see the new access key, choose Show. Your credentials will look something like this: |
| 19 | + - Access Key ID: AKIAIOSFODNEXAMPLEID |
| 20 | + - Secret Access Key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| 21 | + |
| 22 | +## Configure AWS CLI with IAM Credentials |
| 23 | + |
| 24 | +Run the following command in terminal: |
| 25 | +```shell |
| 26 | +aws configure |
| 27 | +``` |
| 28 | + |
| 29 | +Your output should be similar to the one below: |
| 30 | +``` |
| 31 | +AWS Access Key ID [None]: AKIAIOSFODNEXAMPLEID |
| 32 | +AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| 33 | +Default region name [None]: us-east-1 |
| 34 | +Default output format [None]: json |
| 35 | +``` |
| 36 | + |
| 37 | +> NOTE: If you don't have AWS CLI, check out |
| 38 | +[installation guide](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) |
| 39 | + |
| 40 | +## Setup Environment Variables (Will Be Used Later) |
| 41 | + |
| 42 | +Manual Setup (set values in double quotes and run the following command in terminal): |
| 43 | +```shell |
| 44 | +export AWS_ACCOUNT_ID="" ## e.g. 123456789012 |
| 45 | +export AWS_DEFAULT_REGION="" ## e.g. us-east-1 |
| 46 | +``` |
| 47 | + |
| 48 | +### Setup AWS_ACCOUNT_ID Programmatically |
| 49 | + |
| 50 | +Automated Setup (run the following command in terminal): |
| 51 | +```shell |
| 52 | +export AWS_ACCOUNT_ID="$(aws sts get-caller-identity --output=text --query='Account')" |
| 53 | +``` |
| 54 | + |
| 55 | +### Setup AWS_DEFAULT_REGION Programmatically |
| 56 | + |
| 57 | +Automated Setup (run the following command in terminal): |
| 58 | +```shell |
| 59 | +export AWS_DEFAULT_REGION="$(aws configure get region --output=text)" |
| 60 | +``` |
| 61 | + |
| 62 | +## Create Terraform Configurations Using TerraHub |
| 63 | + |
| 64 | +Run the following commands in terminal: |
| 65 | +```shell |
| 66 | +terrahub --help | head -3 |
| 67 | +``` |
| 68 | + |
| 69 | +Your output should be similar to the one below: |
| 70 | +``` |
| 71 | +Usage: terrahub [command] [options] |
| 72 | +
|
| 73 | +[email protected] (built: 2018-10-11T12:33:57.775Z) |
| 74 | +``` |
| 75 | + |
| 76 | +> NOTE: If you don't have TerraHub CLI, check out |
| 77 | +[installation guide](https://www.npmjs.com/package/terrahub) |
| 78 | + |
| 79 | +Run the following commands in terminal: |
| 80 | +```shell |
| 81 | +mkdir demo-terraform-aws |
| 82 | +cd demo-terraform-aws |
| 83 | +terrahub project -n demo-terraform-aws |
| 84 | +``` |
| 85 | + |
| 86 | +Your output should be similar to the one below: |
| 87 | +``` |
| 88 | +✅ Project successfully initialized |
| 89 | +``` |
| 90 | + |
| 91 | +## Create TerraHub Components |
| 92 | + |
| 93 | +Run the following command in terminal: |
| 94 | +```shell |
| 95 | +terrahub component -t aws_iam_role -n iam_role |
| 96 | +terrahub component -t aws_iam_policy -n iam_policy -o ../iam_role |
| 97 | +terrahub component -t aws_iam_role_policy_attachment -n iam_role_policy_attachment_to_role -o ../iam_policy |
| 98 | +terrahub component -t aws_iam_group -n iam_group -o ../iam_policy |
| 99 | +terrahub component -t aws_iam_group_policy_attachment -n iam_role_policy_attachment_to_group -o ../iam_group |
| 100 | +terrahub component -t aws_iam_user -n iam_user -o ../iam_group |
| 101 | +terrahub component -t aws_iam_user_group_membership -n iam_user_group_membership -o ../iam_user |
| 102 | +``` |
| 103 | + |
| 104 | +Your output should be similar to the one below: |
| 105 | +``` |
| 106 | +✅ Done |
| 107 | +``` |
| 108 | + |
| 109 | +## Visualize TerraHub Components |
| 110 | + |
| 111 | +Run the following command in terminal: |
| 112 | +```shell |
| 113 | +terrahub graph |
| 114 | +``` |
| 115 | + |
| 116 | +Your output should be similar to the one below: |
| 117 | +``` |
| 118 | +Project: demo-terraform-aws |
| 119 | + └─ iam_role [path: ./iam_role] |
| 120 | + └─ iam_policy [path: ./iam_policy] |
| 121 | + ├─ iam_group [path: ./iam_group] |
| 122 | + │ ├─ iam_role_policy_attachment_to_group [path: ./iam_role_policy_attachment_to_group] |
| 123 | + │ └─ iam_user [path: ./iam_user] |
| 124 | + │ └─ iam_user_group_membership [path: ./iam_user_group_membership] |
| 125 | + └─ iam_role_policy_attachment_to_role [path: ./iam_role_policy_attachment_to_role] |
| 126 | +``` |
| 127 | + |
| 128 | +## Update Project Config |
| 129 | + |
| 130 | +Run the following command in terminal: |
| 131 | +```shell |
| 132 | +terrahub configure -c terraform.var.account_id="${AWS_ACCOUNT_ID}" |
| 133 | +terrahub configure -c terraform.var.region="${AWS_DEFAULT_REGION}" |
| 134 | +``` |
| 135 | + |
| 136 | +Your output should be similar to the one below: |
| 137 | +``` |
| 138 | +✅ Done |
| 139 | +``` |
| 140 | + |
| 141 | +## Run TerraHub Automation |
| 142 | + |
| 143 | +Run the following command in terminal: |
| 144 | +```shell |
| 145 | +terrahub run -a -y |
| 146 | +``` |
| 147 | + |
| 148 | +Your output should be similar to the one below: |
| 149 | +``` |
| 150 | +``` |
0 commit comments