-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
57 lines (54 loc) · 1.54 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
55
56
57
# Create KMS key for encrypting S3 bucket
resource "aws_kms_key" "terraform_kms_key" {
description = "Used to encrypt Terraform State bucket objects"
enable_key_rotation = true
tags = {
Description = "Used to encrypt Terraform State bucket objects"
Owner = title(var.customer)
}
}
# Create S3 bucket
resource "aws_s3_bucket" "terraform_state_s3_bucket" {
bucket = "${lower(var.customer)}-tfstates"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.terraform_kms_key.arn
sse_algorithm = "aws:kms"
}
}
}
versioning {
enabled = true
}
lifecycle {
prevent_destroy = true
}
tags = {
Description = "Terraform State Files Storage"
Owner = title(var.customer)
}
}
# Block all public access to the bucket
resource "aws_s3_bucket_public_access_block" "example" {
bucket = aws_s3_bucket.terraform_state_s3_bucket.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
# Create DynamoDB table for locking state file when running plan/apply
resource "aws_dynamodb_table" "terraform_state_locking_dynamodb" {
name = "${lower(var.customer)}-terraform-state-locking"
hash_key = "LockID"
read_capacity = 20
write_capacity = 20
attribute {
name = "LockID"
type = "S"
}
tags = {
Description = "Terraform State Files Locking"
Owner = title(var.customer)
}
}