forked from ned1313/Implementing-Terraform-on-AWS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'draft' of https://github.com/ned1313/Implementing-Terra…
…form-on-AWS into draft
- Loading branch information
Showing
15 changed files
with
309 additions
and
18 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
terraform { | ||
backend "s3" { | ||
key = "app/terraform.tfstate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
# Joshua McGee should have permissions to manage EC2, IAM, DynamoDB, | ||
# Lambda, CloudFormation, and RDS | ||
|
||
# Create a profile for Joshua McGee | ||
aws configure --profile app | ||
|
||
# Initialize the terraform configuration | ||
terraform init -backend-config="bucket=BUCKET_NAME" -backend-config="region=REGION_NAME" -backend-config="dynamodb_table=DYNAMODB_TABLE" | ||
|
||
# Plan the terraform deployment | ||
terraform plan -out app.tfplan | ||
|
||
# Apply the deployment | ||
terraform apply "app.tfplan" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform init | ||
|
||
terraform validate | ||
|
||
terraform plan -out state.tfplan | ||
|
||
terraform apply state.tfplan | ||
|
||
# Make note of the s3 bucket name and dynamodb table name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
################################################################################## | ||
# VARIABLES | ||
################################################################################## | ||
|
||
variable "region" { | ||
type = string | ||
default = "us-east-1" | ||
} | ||
|
||
#Bucket variables | ||
variable "aws_bucket_prefix" { | ||
type = string | ||
default = "globo" | ||
} | ||
|
||
variable "aws_dynamodb_table" { | ||
type = string | ||
default = "globo-tfstatelock" | ||
} | ||
|
||
variable "full_access_users" { | ||
type = list(string) | ||
default = [] | ||
|
||
} | ||
|
||
variable "read_only_users" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
################################################################################## | ||
# PROVIDERS | ||
################################################################################## | ||
|
||
provider "aws" { | ||
version = "~>2.0" | ||
region = var.region | ||
profile = "app" | ||
} | ||
|
||
################################################################################## | ||
# RESOURCES | ||
################################################################################## | ||
|
||
resource "random_integer" "rand" { | ||
min = 10000 | ||
max = 99999 | ||
} | ||
|
||
locals { | ||
|
||
dynamodb_table_name = "${var.aws_dynamodb_table}-${random_integer.rand.result}" | ||
bucket_name = "${var.aws_bucket_prefix}-${random_integer.rand.result}" | ||
} | ||
|
||
resource "aws_dynamodb_table" "terraform_statelock" { | ||
name = local.dynamodb_table_name | ||
read_capacity = 20 | ||
write_capacity = 20 | ||
hash_key = "LockID" | ||
|
||
attribute { | ||
name = "LockID" | ||
type = "S" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket" "state_bucket" { | ||
bucket = local.bucket_name | ||
acl = "private" | ||
force_destroy = true | ||
|
||
versioning { | ||
enabled = true | ||
} | ||
|
||
} | ||
|
||
resource "aws_iam_group" "bucket_full_access" { | ||
|
||
name = "${local.bucket_name}-full-access" | ||
|
||
} | ||
|
||
resource "aws_iam_group" "bucket_read_only" { | ||
|
||
name = "${local.bucket_name}-read-only" | ||
|
||
} | ||
|
||
# Add members to the group | ||
|
||
resource "aws_iam_group_membership" "full_access" { | ||
name = "${local.bucket_name}-full-access" | ||
|
||
users = var.full_access_users | ||
|
||
group = aws_iam_group.bucket_full_access.name | ||
} | ||
|
||
resource "aws_iam_group_membership" "read_only" { | ||
name = "${local.bucket_name}-read-only" | ||
|
||
users = var.read_only_users | ||
|
||
group = aws_iam_group.bucket_read_only.name | ||
} | ||
|
||
resource "aws_iam_group_policy" "full_access" { | ||
name = "${local.bucket_name}-full-access" | ||
group = aws_iam_group.bucket_full_access.id | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": "s3:*", | ||
"Resource": [ | ||
"arn:aws:s3:::${local.bucket_name}", | ||
"arn:aws:s3:::${local.bucket_name}/*" | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["dynamodb:*"], | ||
"Resource": [ | ||
"${aws_dynamodb_table.terraform_statelock.arn}" | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_group_policy" "read_only" { | ||
name = "${local.bucket_name}-read-only" | ||
group = aws_iam_group.bucket_read_only.id | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:Get*", | ||
"s3:List*" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::${local.bucket_name}", | ||
"arn:aws:s3:::${local.bucket_name}/*" | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
################################################################################## | ||
# OUTPUT | ||
################################################################################## | ||
|
||
output "s3_bucket" { | ||
value = aws_s3_bucket.state_bucket.bucket | ||
} | ||
|
||
output "dynamodb_statelock" { | ||
value = aws_dynamodb_table.terraform_statelock.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
full_access_users = ["JoMcGee"] | ||
|
||
read_only_users = ["ElVasquez"] | ||
|
||
aws_bucket_prefix = "globo-app" | ||
|
||
aws_dynamodb_table = "globo-app-tfstatelock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
terraform { | ||
backend "s3" { | ||
key = "lambda/terraform.tfstate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Rename terraform.tfvars.example to terraform.tfvars and update values | ||
|
||
# Initialize the terraform configuration | ||
terraform init -backend-config="bucket=_BUCKET_NAME" -backend-config="region=REGION_NAME" -backend-config="dynamodb_table=DYNAMODB_TABLE" | ||
|
||
# Plan the terraform deployment | ||
terraform plan -out stack.tfplan | ||
|
||
# Apply the deployment | ||
terraform apply "stack.tfplan" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
network_state_bucket = "STATE_BUCKET_NAME" |
Oops, something went wrong.