Skip to content

Commit

Permalink
add record of state storage resource addition
Browse files Browse the repository at this point in the history
  • Loading branch information
leej3 committed Jul 31, 2024
1 parent 7ecb10b commit 888a5e7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
16 changes: 16 additions & 0 deletions web_api/terraform/state_storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Created bucket and table manually:

```
aws s3api create-bucket --bucket osm-terraform-storage --region us-east-1
aws s3api list-buckets
aws s3api list-buckets --region us-east-1
aws s3api put-bucket-versioning --bucket osm-terraform-storage --versioning-configuration Status=Enabled
aws s3 cp state-storage.tf s3://osm-terraform-storage/test.tf
aws s3 rm s3://osm-terraform-storage --recursive
# Failed: aws dynamodb create-table --table-name terraform-locks --attribute-definitions AttributeName=LockID,AttributeType=S --key-schema AttributeName=LockID,KeyType=HASH --billing-mode PAY_PER_REQUEST --region us-east-1
# Created dynamodb-policy.json
aws iam create-policy --policy-name DynamoDBFullAccess --policy-document file://dynamodb-policy.json
aws iam attach-user-policy --policy-arn arn:aws:iam::507624629289:policy/DynamoDBFullAccess --user-name osm
aws iam list-attached-user-policies --user-name osm
aws dynamodb create-table --table-name terraform-locks --attribute-definitions AttributeName=LockID,AttributeType=S --key-schema AttributeName=LockID,KeyType=HASH --billing-mode PAY_PER_REQUEST --region us-east-1
```
29 changes: 29 additions & 0 deletions web_api/terraform/state_storage/dynamodb-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:CreateTable",
"dynamodb:DeleteTable",
"dynamodb:DescribeTable",
"dynamodb:ListTables",
"dynamodb:UpdateTable",
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:DeleteItem",
"dynamodb:Query",
"dynamodb:Scan"
],
"Resource": "arn:aws:dynamodb:us-east-1:507624629289:table/terraform-locks"
},
{
"Effect": "Allow",
"Action": [
"dynamodb:ListTables",
"dynamodb:ListTagsOfResource"
],
"Resource": "*"
}
]
}
46 changes: 46 additions & 0 deletions web_api/terraform/state_storage/state-storage.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_s3_bucket" "tf_state" {
bucket = "osm-storage"
versioning {
enabled = true
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
lifecycle_rule {
id = "tf_state"
enabled = true
transition {
days = 30
storage_class = "STANDARD_IA"
}
expiration {
days = 365
}
}
tags = {
Name = "terraform-state-storage"
}
}

resource "aws_dynamodb_table" "tf_locks" {
name = "terraform-locks"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"

attribute {
name = "LockID"
type = "S"
}

tags = {
Name = "terraform-state-locks"
}
}

0 comments on commit 888a5e7

Please sign in to comment.