Skip to content

Commit d6e5686

Browse files
authored
Merge pull request #2 from TerraHubCorp/dev
AWS Demo
2 parents 2e18d10 + 7dc57f9 commit d6e5686

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+964
-4
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@
55
*.tfstate
66
*.tfstate.*
77

8-
# .tfvars files
9-
*.tfvars

.terrahub.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## project config
2+
project:
3+
name: demo-terraform-aws
4+
code: 7356626c
5+
provider: aws
6+
include:
7+
- '.'
8+
exclude:
9+
- '**/.terraform/*'
10+
- '**/node_modules/*'
11+
12+
## terraform config
13+
terraform:
14+
varFile:
15+
- default.tfvars
16+
var:
17+
account_id: 123456789012
18+
region: us-east-1

README.md

Lines changed: 150 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,150 @@
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+
```

iam_group/.terrahub.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## local config
2+
component:
3+
name: 'iam_group'
4+
dependsOn:
5+
- '../iam_policy'
6+
7+
## ci config
8+
ci:
9+
mapping:
10+
- '.'

iam_group/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# iam_group
2+
3+
Provides an IAM group.
4+
5+
## input variables
6+
7+
| Name | Description | Type | Default | Required |
8+
|------|-------------|:----:|:-----:|:-----:|
9+
|account_id|The id of AWS account.|string||Yes|
10+
|region|This is the AWS region.|string|us-east-1|Yes|
11+
|iam_group_name|The group's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: =,.@-_.. group names are not distinguished by case.|string|{{ name }}|No|
12+
|iam_group_path|Path in which to create the group.|string|/|No|
13+
|custom_tags|Custom tags.|map||No|
14+
|default_tags|Default tags.|map|{"ThubName"= "{{ name }}","ThubCode"= "{{ code }}","ThubEnv"= "default","Description" = "Managed by TerraHub"}|No|
15+
16+
## output parameters
17+
18+
| Name | Description | Type |
19+
|------|-------------|:----:|
20+
|id|The group's ID.|string|
21+
|thub_id|The group's ID (hotfix for issue hashicorp/terraform#[7982]).|string|
22+
|arn|The ARN assigned by AWS for this group.|string|
23+
|name|The group's name.|string|
24+
|path|The path of the group in IAM.|string|
25+
|unique_id|The unique ID assigned by AWS.|string|

iam_group/default.tfvars

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Specify default values for variables defined in variables.tf
2+
3+
############
4+
# provider #
5+
############
6+
account_id = "123456789012"
7+
region = "us-east-1"
8+
9+
#############
10+
# top level #
11+
#############
12+
iam_group_name = "iam_group"
13+
iam_group_path = "/"
14+
15+
##########
16+
# custom #
17+
##########

iam_group/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "aws_iam_group" "iam_group" {
2+
name = "${var.iam_group_name}"
3+
path = "${var.iam_group_path}"
4+
}

iam_group/output.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Define list of variables to be output
2+
3+
output "id" {
4+
value = "${aws_iam_group.iam_group.id}"
5+
}
6+
7+
output "thub_id" {
8+
value = "${aws_iam_group.iam_group.id}"
9+
}
10+
11+
output "arn" {
12+
value = "${aws_iam_group.iam_group.arn}"
13+
}
14+
15+
output "name" {
16+
value = "${aws_iam_group.iam_group.name}"
17+
}
18+
19+
output "path" {
20+
value = "${aws_iam_group.iam_group.path}"
21+
}
22+
23+
output "unique_id" {
24+
value = "${aws_iam_group.iam_group.unique_id}"
25+
}

iam_group/provider.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "aws" {
2+
version = "~> 1.0"
3+
region = "${var.region}"
4+
5+
allowed_account_ids = ["${var.account_id}"]
6+
}

iam_group/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Define list of variables to be used in main.tf
2+
3+
############
4+
# provider #
5+
############
6+
variable "account_id" {
7+
description = "Allowed AWS account ID, to prevent you from mistakenly using an incorrect one (and potentially end up destroying a live environment)."
8+
}
9+
10+
variable "region" {
11+
description = "This is the AWS region."
12+
}
13+
14+
#############
15+
# top level #
16+
#############
17+
variable "iam_group_name" {
18+
description = "he group's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: =,.@-_.. Group names are not distinguished by case."
19+
}
20+
21+
variable "iam_group_path" {
22+
description = "Path in which to create the group."
23+
}

0 commit comments

Comments
 (0)