forked from tf-mod/terraform-aws-tfbackend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
62 lines (51 loc) · 1.35 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
data "aws_partition" "current" {}
# DynamoDB table for lock info storage
resource "aws_dynamodb_table" "terraform_lock" {
name = var.dynamodb_table
read_capacity = var.dynamodb_read_capacity
write_capacity = var.dynamodb_write_capacity
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
tags = var.tags
lifecycle {
ignore_changes = [
read_capacity,
write_capacity,
]
}
}
# S3 bucket for storing terraform state
resource "aws_s3_bucket" "terraform_state" {
bucket = var.bucket_name
}
resource "aws_s3_bucket_versioning" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = aws_s3_bucket.terraform_state.id
policy = data.aws_iam_policy_document.bucket_policy.json
}
data "aws_iam_policy_document" "bucket_policy" {
statement {
actions = [
"s3:ListBucket",
"s3:GetObject",
]
resources = [
format("arn:%s:s3:::%s/*", data.aws_partition.current.partition, var.bucket_name),
format("arn:%s:s3:::%s", data.aws_partition.current.partition, var.bucket_name),
]
principals {
type = "AWS"
identifiers = [
format("arn:%s:iam::%s:root", data.aws_partition.current.partition, var.aws_account_id)
]
}
}
}