-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
72 lines (62 loc) · 1.28 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
72
data "aws_region" "current" {}
resource "random_string" "rand" {
length = 24
special = false
upper = false
}
locals {
namespace = substr(join("-", [var.namespace, random_string.rand.result]), 0, 24)
}
resource "aws_resourcegroups_group" "resourcegroups_group" {
name = "${local.namespace}-group"
resource_query {
query = <<-JSON
{
"ResourceTypeFilters": [
"AWS::AllSupported"
],
"TagFilters": [
{
"Key": "ResourceGroup",
"Values": ["${local.namespace}"]
}
]
}
JSON
}
}
resource "aws_kms_key" "kms_key" {
tags = {
ResourceGroup = local.namespace
}
}
resource "aws_s3_bucket" "s3_bucket" {
bucket = "${local.namespace}-state-bucket"
force_destroy = var.force_destroy_state
versioning {
enabled = true
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
kms_master_key_id = aws_kms_key.kms_key.arn
}
}
}
tags = {
ResourceGroup = local.namespace
}
}
resource "aws_dynamodb_table" "dynamodb_table" {
name = "${local.namespace}-state-lock"
hash_key = "LockID"
billing_mode = "PAY_PER_REQUEST"
attribute {
name = "LockID"
type = "S"
}
tags = {
ResourceGroup = local.namespace
}
}