forked from telia-oss/terraform-aws-terraform-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
71 lines (59 loc) · 1.53 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# ------------------------------------------------------------------------------
# Resources
# ------------------------------------------------------------------------------
resource "aws_s3_bucket" "state" {
bucket = "${var.name_prefix}-terraform-state"
tags = merge(
var.tags,
{
"Name" = "${var.name_prefix}-terraform-state"
},
)
}
resource "aws_s3_bucket_versioning" "state" {
bucket = aws_s3_bucket.state.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_acl" "state" {
bucket = aws_s3_bucket.state.id
acl = "private"
}
resource "aws_s3_bucket_public_access_block" "state" {
bucket = aws_s3_bucket.state.id
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
ignore_public_acls = true
}
resource "aws_dynamodb_table" "lock" {
name = "${var.name_prefix}-terraform-state"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
tags = merge(
var.tags,
{
"Name" = "${var.name_prefix}-terraform-state"
},
)
}
resource "aws_kms_key" "encrypt" {
description = "Terraform state KMS key."
deletion_window_in_days = 30
policy = var.kms_key_policy
tags = merge(
var.tags,
{
"Name" = "${var.name_prefix}-terraform-state-kms-key"
},
)
}
resource "aws_kms_alias" "encrypt-alias" {
name = "alias/${var.name_prefix}-terraform-state-encryption-key"
target_key_id = aws_kms_key.encrypt.key_id
}