2 Commits

Author SHA1 Message Date
Max
08b1b8f641 feat: init tf 2025-01-09 15:20:49 -05:00
Max
3fb6801188 feat: portfolio terraform 2025-01-09 15:15:26 -05:00
6 changed files with 161 additions and 1 deletions

44
.gitignore vendored
View File

@@ -3,4 +3,46 @@ _site
.jekyll-cache
vendor
.vscode
.DS_Store
.DS_Store
secrets
secret.tfvars
# ---> Terraform
# Local .terraform directories
.terraform
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
crash.*.log
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json
# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# Ignore CLI configuration files
*.terraformrc
terraform.rc
# ---------------------------------------------------------------------------- #
# Custom ignores.

View File

@@ -1,5 +1,15 @@
version: 3
env: { TF: terraform -chdir=terraform }
silent: true
tasks:
tf/init: $TF init -backend-config=../secrets/backend.json
tf/plan: $TF plan
tf/destroy: $TF destroy
tf/format: $TF fmt -recursive
tf/apply:
- $TF apply
- $TF output -json > secrets/terraform.json
action: act -W .gitea/workflows --container-architecture linux/amd64

24
terraform/.terraform.lock.hcl generated Normal file
View File

@@ -0,0 +1,24 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "5.83.0"
hashes = [
"h1:uh/57vwauk96J9HjqvjmWV9sLXbX0YXbYnqUBWooiwQ=",
"zh:03a1d4cb151efd9279a3348ecb5e26fe99eb5d217b254e544c7f768a03020d0e",
"zh:07637e75abd0809454d9b51b4499059e6fd3eb58d4723c99bc71d21595a9b897",
"zh:415868ead3d9b9527418c68468972dd0c9614e69240133d8b1d77641259eb396",
"zh:52f343f08881fc88fcbd731cdf480c02edd6eb335934107bbcfb0d97c2a575df",
"zh:60d19aed16142fce6fd95087d9de8d8f59681db98588f9384112045ce533f3ce",
"zh:62775ba5933b41d00df59fe7ae02027d328ccedc06ff5363ff8d2f48633c4012",
"zh:95c7a13b5ef625a672f0ac94d1a20858f60bf09a6517b180f031b707f37d862d",
"zh:9adf0d9f349e692b9f51375713c316d28d217f72d2b86deb49e48c3834a41539",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:b605deb6d3eff97218b6b16b153038ac8e7bd0b8506ae469f2368281dca46cab",
"zh:b8542b3672bca0c6ed522b8f65d92ef5720786301abc7d7dae07f07296398b4c",
"zh:d975790f409234f9791633adba3ffcfbb2526bc04aed1f379fc8f90370366907",
"zh:e621bd43f3a46f122ec450828d590ee2f34c0be5603120876ddfc218861b1802",
"zh:e87e2989e99aa21bbfdb603e1325afe11af126684c64821eca8d014f8b762ca5",
"zh:f7f6f149d6e1e9d4b979b23b248df14bfe3c497052ec41a6dd40d19bcd9cde9a",
]
}

59
terraform/main.tf Normal file
View File

@@ -0,0 +1,59 @@
# Create the S3 bucket.
resource "aws_s3_bucket" "portfolio_bucket" {
bucket = var.bucket_name
tags = {
Name = "Portfolio Bucket"
Environment = "Production"
}
}
resource "aws_s3_bucket_public_access_block" "portfolio_bucket_access" {
bucket = aws_s3_bucket.portfolio_bucket.id
block_public_acls = false
block_public_policy = false
}
resource "aws_s3_bucket_versioning" "portfolio_bucket_access_versioning" {
bucket = aws_s3_bucket.portfolio_bucket.id
versioning_configuration {
status = "Disabled"
}
}
#------------------------------------------------------------------------------#
# Give a user access.
data "aws_iam_policy_document" "portfolio_bucket_policy_doc" {
statement {
effect = "Allow"
actions = ["s3:*", "s3-object-lambda:*"]
resources = [
"${aws_s3_bucket.portfolio_bucket.arn}/*",
"${aws_s3_bucket.portfolio_bucket.arn}"
]
}
}
resource "aws_iam_policy" "portfolio_bucket_policy" {
name = "${var.role_name}Policy"
description = "The policy that manages the Portfolio Bucket."
policy = data.aws_iam_policy_document.portfolio_bucket_policy_doc.json
}
resource "aws_iam_user" "portfolio_bucket_user" {
name = "${var.role_name}User"
}
resource "aws_iam_user_policy_attachment" "portfolio_bucket_attachment" {
user = aws_iam_user.portfolio_bucket_user.name
policy_arn = aws_iam_policy.portfolio_bucket_policy.arn
}
resource "aws_iam_access_key" "portfolio_bucket_key" {
user = aws_iam_user.portfolio_bucket_user.name
}

16
terraform/outputs.tf Normal file
View File

@@ -0,0 +1,16 @@
output "access_region" {
value = aws_s3_bucket.portfolio_bucket.region
description = "This is the region of the bucket."
}
output "access_id" {
value = aws_iam_access_key.portfolio_bucket_key.id
description = "This is the access ID to modify the bucket."
sensitive = true
}
output "access_secret" {
value = aws_iam_access_key.portfolio_bucket_key.secret
description = "This is the access secret to modify the bucket."
sensitive = true
}

9
terraform/variables.tf Normal file
View File

@@ -0,0 +1,9 @@
variable "bucket_name" {
type = string
description = "The name of the bucket to create."
}
variable "role_name" {
type = string
description = "The base name for the role to modify the bucket."
}