01: infra
This commit is contained in:
1 parent
ec9bb74be0
commit
341cd05ac5
71 files changed
+2058
-1
No files matched your search
@@ -0,0 +1,97 @@
|
||||
# Object Storage module for HAPI
|
||||
# Creates buckets for uploads and Terraform state
|
||||
|
||||
resource "linode_object_storage_bucket" "uploads" {
|
||||
for_each = toset(["staging", "production"])
|
||||
|
||||
label = "hapi-uploads-${each.key}"
|
||||
cluster = var.linode_object_storage_cluster
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
depends_on = [linode_object_storage_cluster.this]
|
||||
}
|
||||
|
||||
resource "linode_object_storage_bucket" "state" {
|
||||
for_each = toset(["staging", "production"])
|
||||
|
||||
label = "hapi-terraform-state-${each.key}"
|
||||
cluster = var.linode_object_storage_cluster
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
depends_on = [linode_object_storage_cluster.this]
|
||||
}
|
||||
|
||||
resource "linode_object_storage_cluster" "this" {
|
||||
label = "hapi-object-storage"
|
||||
region = var.linode_region
|
||||
}
|
||||
|
||||
# Bucket configurations
|
||||
locals {
|
||||
bucket_config = {
|
||||
staging = {
|
||||
uploads = {
|
||||
label = "hapi-uploads-staging"
|
||||
policy = jsonencode({
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": { "AWS": ["*"] },
|
||||
"Action": ["s3:GetObject", "s3:PutObject"],
|
||||
"Resource": ["arn:aws:s3:::hapi-uploads-staging/*"]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
state = {
|
||||
label = "hapi-terraform-state-staging"
|
||||
}
|
||||
}
|
||||
production = {
|
||||
uploads = {
|
||||
label = "hapi-uploads-production"
|
||||
policy = jsonencode({
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": { "AWS": ["*"] },
|
||||
"Action": ["s3:GetObject", "s3:PutObject"],
|
||||
"Resource": ["arn:aws:s3:::hapi-uploads-production/*"]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
state = {
|
||||
label = "hapi-terraform-state-production"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "endpoint" {
|
||||
description = "Object Storage endpoint"
|
||||
value = "https://${var.linode_region}.linodeobjects.com"
|
||||
}
|
||||
|
||||
output "access_key" {
|
||||
description = "Object Storage access key"
|
||||
value = var.object_storage_access_key
|
||||
}
|
||||
|
||||
output "secret_key" {
|
||||
description = "Object Storage secret key"
|
||||
value = var.object_storage_secret_key
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "state_bucket_name" {
|
||||
description = "Name of the Terraform state bucket"
|
||||
value = "hapi-terraform-state-${var.environment}"
|
||||
}
|
||||
|
||||
output "uploads_bucket_name" {
|
||||
description = "Name of the uploads bucket"
|
||||
value = "hapi-uploads-${var.environment}"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Storage module variables
|
||||
linode_region = "us-east"
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
environment = "staging"
|
||||
@@ -0,0 +1,42 @@
|
||||
# Variables for Object Storage module
|
||||
|
||||
variable "linode_region" {
|
||||
description = "Linode region for Object Storage"
|
||||
type = string
|
||||
default = "us-east"
|
||||
}
|
||||
|
||||
variable "linode_object_storage_cluster" {
|
||||
description = "Linode Object Storage cluster"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "object_storage_access_key" {
|
||||
description = "Object Storage access key"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "object_storage_secret_key" {
|
||||
description = "Object Storage secret key"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags for all resources"
|
||||
type = map(string)
|
||||
default = {
|
||||
ManagedBy = "terraform"
|
||||
Project = "hapi"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user