2020-02-22 23:41:01 +00:00
|
|
|
resource "aws_iam_user" "terraform" {
|
|
|
|
name = "terraform"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_s3_bucket" "tfstate" {
|
2020-02-22 23:43:00 +00:00
|
|
|
bucket = "0rng-terraform"
|
2024-01-07 13:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_s3_bucket_versioning" "tfstate" {
|
|
|
|
bucket = aws_s3_bucket.tfstate.id
|
|
|
|
|
|
|
|
versioning_configuration {
|
|
|
|
status = "Enabled"
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 18:26:18 +01:00
|
|
|
|
2024-01-07 13:49:35 +00:00
|
|
|
resource "aws_s3_bucket_server_side_encryption_configuration" "tfstate" {
|
|
|
|
bucket = aws_s3_bucket.tfstate.bucket
|
|
|
|
|
|
|
|
rule {
|
|
|
|
apply_server_side_encryption_by_default {
|
|
|
|
sse_algorithm = "AES256"
|
|
|
|
}
|
2020-04-02 18:26:18 +01:00
|
|
|
}
|
2024-01-07 13:49:35 +00:00
|
|
|
}
|
2020-04-02 18:26:18 +01:00
|
|
|
|
2024-01-07 13:49:35 +00:00
|
|
|
resource "aws_s3_bucket_lifecycle_configuration" "tfstate" {
|
|
|
|
bucket = aws_s3_bucket.tfstate.id
|
|
|
|
|
|
|
|
rule {
|
|
|
|
id = "Delete old non-current versions"
|
|
|
|
status = "Enabled"
|
2020-04-02 18:26:18 +01:00
|
|
|
|
|
|
|
noncurrent_version_expiration {
|
2024-01-07 13:49:35 +00:00
|
|
|
noncurrent_days = 30
|
2020-04-02 18:26:18 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-07 13:49:35 +00:00
|
|
|
}
|
2020-04-02 18:26:18 +01:00
|
|
|
|
2024-01-07 13:49:35 +00:00
|
|
|
resource "aws_s3_bucket_acl" "tfstate" {
|
|
|
|
bucket = aws_s3_bucket.tfstate.id
|
|
|
|
acl = "private"
|
2020-02-22 23:41:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-07 12:58:16 +00:00
|
|
|
resource "aws_iam_user_policy" "modify-terraform-user" {
|
|
|
|
name = "modify-terraform-user"
|
2020-02-22 23:43:00 +00:00
|
|
|
user = aws_iam_user.terraform.name
|
2020-02-22 23:41:01 +00:00
|
|
|
|
2020-02-22 23:43:00 +00:00
|
|
|
policy = <<EOF
|
2020-02-22 23:41:01 +00:00
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
2024-01-07 12:58:16 +00:00
|
|
|
"Sid": "ModifyTerraformUser",
|
2020-02-22 23:41:01 +00:00
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "iam:*",
|
2024-01-07 12:58:16 +00:00
|
|
|
"Resource": "*"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "aws_iam_policy" "terraform_state" {
|
|
|
|
name = "terraform-state"
|
|
|
|
|
|
|
|
policy = <<EOF
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
2020-02-22 23:41:01 +00:00
|
|
|
{
|
2024-01-07 12:58:16 +00:00
|
|
|
"Sid": "TerraformState",
|
2020-02-22 23:41:01 +00:00
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "s3:*",
|
|
|
|
"Resource": [
|
|
|
|
"${aws_s3_bucket.tfstate.arn}",
|
|
|
|
"${aws_s3_bucket.tfstate.arn}/*"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
2024-01-07 12:58:16 +00:00
|
|
|
|
|
|
|
resource "aws_iam_user_policy_attachment" "terraform-state" {
|
|
|
|
for_each = toset([
|
2024-01-07 13:04:09 +00:00
|
|
|
aws_iam_user.terraform.name,
|
|
|
|
aws_iam_user.minio.name,
|
2024-01-07 12:58:16 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
user = each.key
|
|
|
|
policy_arn = aws_iam_policy.terraform_state.arn
|
|
|
|
}
|