-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
54 lines (49 loc) · 1.57 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Spin up neccessary resources for your terraform state
resource "aws_kms_key" "tf_state_encryption_key" {
description = "This key is used to encrypt tf_state bucket objects"
deletion_window_in_days = 10
}
resource "aws_s3_bucket" "terraform_states" {
bucket = "tf-states-s3backend"
}
# Enable versioning so we can see the full revision history of our
# state files
resource "aws_s3_bucket_versioning" "tf_versioning" {
bucket = aws_s3_bucket.terraform_states.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "tf_state_encryption" {
bucket = aws_s3_bucket.terraform_states.bucket
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.tf_state_encryption_key.arn
sse_algorithm = "aws:kms"
}
}
}
resource "aws_dynamodb_table" "terraform_state_lock" {
name = "tf-lock-table"
read_capacity = 1
write_capacity = 1
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
# Comment out this block on first deploy to generate the s3 bucket and dynamo table.
# We will be able to import them later and rerun this code once they exist
terraform {
backend "s3" {
# Replace this with your bucket name!
bucket = "tf-states-s3backend"
key = "main.tf"
region = "us-east-1"
encrypt = true
profile = "default"
dynamodb_table = "tf-lock-table"
shared_credentials_file = "$HOME/.aws/credentials"
}
}