-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
57 lines (45 loc) · 1.32 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
locals {
aws_logs_path = "/AWSLogs/${data.aws_caller_identity.identity.account_id}"
prefix = "${var.project}-${var.environment}"
}
data "aws_caller_identity" "identity" {}
data "aws_partition" "current" {}
resource "aws_kms_key" "backend" {
description = "OpenTofu backend encryption key for ${var.project} ${var.environment}"
deletion_window_in_days = var.key_recovery_period
enable_key_rotation = true
policy = templatefile("${path.module}/templates/key-policy.json.tftpl", {
account_id : data.aws_caller_identity.identity.account_id,
partition : data.aws_partition.current.partition,
bucket_arn : aws_s3_bucket.tfstate.arn
})
tags = var.tags
}
resource "aws_kms_alias" "backend" {
name = "alias/${var.project}/${var.environment}/backend"
target_key_id = aws_kms_key.backend.id
}
resource "aws_dynamodb_table" "tfstate_lock" {
name = "${var.environment}.tfstate"
read_capacity = 1
write_capacity = 1
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
server_side_encryption {
enabled = true
kms_key_arn = aws_kms_key.backend.arn
}
point_in_time_recovery {
enabled = true
}
tags = var.tags
}
output "bucket" {
value = aws_s3_bucket.tfstate.id
}
output "kms_key" {
value = aws_kms_key.backend.id
}