Skip to content

Commit cdc2b55

Browse files
committedJul 26, 2020
🏗️
1 parent c80c4eb commit cdc2b55

File tree

17 files changed

+140
-2
lines changed

17 files changed

+140
-2
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/terraform-test
2+
/.terraform.tfstate.lock.info

‎README.md

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Automating AWS with Terraform
22

3+
- [x] [Launch an ec2 instance](/launch-ec2-instance)
4+
- [X] [Create an s3 bucket](/create-s3-bucket)
5+
- [x] [Create an s3 backend state](/create-s3-backend-state)
6+
- [X] [Create an IAM group and policy](/create-iam-group-policy)
7+
- [x] [Add users to an IAM group](/add-users-to-iam-group)
8+
9+
## External Resources
10+
[Amazon EC2 AMI Locator](https://cloud-images.ubuntu.com/locator/ec2/)
11+
312
## Pre-requisite Setup
413

514
#### AWS Account - Free Tier
@@ -28,7 +37,8 @@
2837
3. linux: [instructions](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html)
2938

3039
#### AWS CLI configuration
31-
1. aws basic configuration
40+
aws credentials configured locally
41+
these credentials are stored in `~/.aws/credentials`
3242
```
3343
aws configure
3444
AWS Access Key ID [None]: <access key>
@@ -41,4 +51,43 @@
4151
#### Terraform installation
4252
1. mac: `brew install terraform` | `terraform -help`
4353
2. windows: `choco install terraform` | `terraform -help`
44-
3. linux: [download](https://www.terraform.io/downloads.html) | `echo $PATH` | ` mv ~/Downloads/terraform /usr/local/bin/` | `terraform -help`
54+
3. linux: [download](https://www.terraform.io/downloads.html) | `echo $PATH` | ` mv ~/Downloads/terraform /usr/local/bin/` | `terraform -help`
55+
56+
57+
## Local Setup
58+
59+
clone the repo and navigate to the directory
60+
```
61+
git clone https://github.com/ari-hacks/terraform-aws-automation.git
62+
cd terraform-aws-automation
63+
```
64+
65+
In the terminal `cd` into one of the directories from the list above
66+
67+
Run these commands to provision with Terraform
68+
69+
```HCL
70+
#Initialize Terraform
71+
terraform init
72+
```
73+
74+
```HCL
75+
#Check the plan to make sure the configuration will do what we expect it to do
76+
terraform plan
77+
```
78+
79+
```HCL
80+
#Check the plan to make sure the configuration will do what we expect it to do
81+
terraform apply
82+
```
83+
84+
```HCL
85+
#Check the resource is up
86+
terraform stat show 'type.name'
87+
```
88+
89+
```HCL
90+
#Tear down all provisions
91+
terraform destroy
92+
```
93+

‎add-users-to-iam-group/main.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
resource "aws_iam_user" "admin_example_1" {
6+
name = "admin_example_1"
7+
}
8+
9+
resource "aws_iam_user" "admin_example_2" {
10+
name = "admin_example_2"
11+
}
12+
13+
resource "aws_iam_group_membership" "admin-user-group-example" {
14+
name = "admin-user-group-example"
15+
users = [
16+
aws_iam_user.admin_example_1.name,
17+
aws_iam_user.admin_example_2.name,
18+
]
19+
group = "administrators"
20+
}

‎add-users-to-iam-group/outputs.tf

Whitespace-only changes.

‎add-users-to-iam-group/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "region" {
2+
description = "AWS region"
3+
default = "us-east-2"
4+
}

‎create-iam-group-policy/maint.tf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
resource "aws_iam_group" "admin_example" {
6+
name = "administrators"
7+
}
8+
9+
resource "aws_iam_policy_attachment" "admin-example" {
10+
name = "admin-example"
11+
groups = [aws_iam_group.admin_example.name]
12+
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
13+
}

‎create-iam-group-policy/outputs.tf

Whitespace-only changes.

‎create-iam-group-policy/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "region" {
2+
description = "AWS region"
3+
default = "us-east-2"
4+
}

‎create-s3-backend-state/main.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
terraform {
2+
backend "s3" {
3+
bucket = "bucket-example-tmed232323"
4+
key = "terraform-aws-automation/create-s3-backend-state/terraform.tfstate"
5+
}
6+
}

‎create-s3-backend-state/outputs.tf

Whitespace-only changes.

‎create-s3-backend-state/variables.tf

Whitespace-only changes.

‎create-s3-bucket/main.tf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
resource "aws_s3_bucket" "b_example" {
6+
bucket = "bucket-example-tmed232323"
7+
force_destroy = true
8+
acl = "private"
9+
10+
versioning {
11+
enabled = true
12+
}
13+
}

‎create-s3-bucket/outputs.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "s3-bucket" {
2+
value = aws_s3_bucket.b_example.bucket
3+
}

‎create-s3-bucket/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "region" {
2+
description = "AWS region"
3+
default = "us-east-2"
4+
}

‎launch-ec2-instance/main.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
terraform {
6+
required_version = ">= 0.12"
7+
}
8+
9+
resource "aws_instance" "ec2_example" {
10+
ami = var.ami
11+
instance_type = "t2.micro"
12+
}

‎launch-ec2-instance/outputs.tf

Whitespace-only changes.

‎launch-ec2-instance/variables.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "region" {
2+
description = "AWS region"
3+
default = "us-east-2"
4+
}
5+
6+
variable "ami" {
7+
default = "ami-0c8110836d05ad7bd"
8+
}

0 commit comments

Comments
 (0)
Please sign in to comment.