-
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.
Implement remote state file
- Loading branch information
Showing
10 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
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,22 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# File:: state.tf | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Configure terraform to store it's state file remote | ||
# | ||
|
||
#-- | ||
terraform { | ||
backend "s3" { | ||
bucket = "en-infra-aws-remote-state" | ||
key = "en_infra_aws/terraform.tfstate" | ||
region = "us-east-1" | ||
lock_table = "en-infra-aws-remote-state-lock" | ||
} | ||
} |
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,37 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# File:: Makefile | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Helper that will help us manage our 'terraform' plans. | ||
|
||
.PHONY: all test get info plan apply destroy | ||
|
||
all: plan apply | ||
test: plan | ||
|
||
get: | ||
terraform get | ||
|
||
info: | ||
for resursa in $$(terraform state list); do \ | ||
echo -e "\n\n========================\n$$resursa\n------------------------"; \ | ||
terraform state show $$resursa; \ | ||
done | ||
|
||
plan: | ||
terraform plan -var-file ../DevOpsVPC/infrastructure.conf | ||
|
||
apply: | ||
terraform apply -var-file ../DevOpsVPC/infrastructure.conf | ||
|
||
destroy: | ||
terraform plan -destroy -var-file ../DevOpsVPC/infrastructure.conf -out=statefiles/destroy.tfplan -state=statefiles/terraform.tfstate | ||
terraform apply statefiles/destroy.tfplan | ||
mv -f statefiles/terraform.tfstate statefiles/terraform.tfstate.old | ||
mv -f terraform.tfstate statefiles/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 @@ | ||
Provisioning of the AWS resources required for remote state file storage and locking. |
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,25 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# File:: s3_bucket.tf | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Sets up an S3 Bucket for RemoteState Storage | ||
# | ||
|
||
#-- | ||
resource "aws_dynamodb_table" "terraform_state_lock" { | ||
name = "${var.statefile_dynamo}" | ||
read_capacity = 10 | ||
write_capacity = 10 | ||
hash_key = "LockID" | ||
|
||
attribute { | ||
name = "LockID" | ||
type = "S" | ||
} | ||
} |
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,20 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# File:: providers.tf | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Sets up aws account access credentials | ||
# and regional preference | ||
# | ||
|
||
#-- | ||
provider "aws" { | ||
region = "${var.aws_region}" | ||
#-- must be fullpath, ~ is not evaluated | ||
shared_credentials_file = "${pathexpand("~/.aws/credentials")}" | ||
} |
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,25 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# File:: s3_bucket.tf | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Sets up an S3 Bucket for RemoteState Storage | ||
# | ||
|
||
#-- | ||
resource "aws_s3_bucket" "terraform_state" { | ||
bucket = "${var.statefile_bucket}" | ||
|
||
versioning { | ||
enabled = true | ||
} | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} |
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,34 @@ | ||
|
||
# Project Name:: en_infra_aws | ||
# File:: variables.tf | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Variables we're using with their description. | ||
# If a default value is set, the variable is optional. | ||
# Otherwise, the variable is required. | ||
|
||
#-- Naming | ||
variable "aws_region" { | ||
description = "AWS region" | ||
type = "string" | ||
default = "us-east-1" | ||
} | ||
|
||
#-- | ||
variable "statefile_bucket" { | ||
description = "Name of the S3 bucket where we will store our statefile" | ||
type = "string" | ||
default = "en-infra-aws-remote-state" | ||
} | ||
|
||
#-- | ||
variable "statefile_dynamo" { | ||
description = "Name of the DynamoDB table where we will store our locking" | ||
type = "string" | ||
default = "en-infra-aws-remote-state-lock" | ||
} |