Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Backend2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# configure S3 Buckect
resource "aws_s3_bucket" "terraform_state" {
bucket = "mys3-bucket-terraform-state"
versioning {
enabled = true
}
server_side_encryption_configuration { //make sure the state file is ecrypted
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}

# setup a locking mechanism so that only one user can make changes at a given time --use DynamoDB table
resource "aws_dynamodb_table" "terraform_DynamoDb-Example" {
name = "terraform-State-Locking"
hash_key = "LockID"
billing_mode = "PAY_PER_REQUEST"
attribute {
name = "LockID"
type = "S"
}
}


# setup the backend - first run the terraform apply without the below configure..comment it out first,
# then run another init to migrate from local to S3 the backend
terraform {
backend "s3" {
bucket = "mys3-bucket-terraform-state"
key = "global/S3/ynwa-website.tfstate" //path i want to use for my state file
region = "us-east-1"
dynamodb_table = "terraform-State-Locking"
encrypt = true
profile = "terraform-user"
}
}