Add infrastructure bucket for storing assets

This commit is contained in:
2024-09-28 19:15:56 +02:00
parent 52d6d85203
commit 4de62d7334
17 changed files with 414 additions and 28 deletions
+1
View File
@@ -0,0 +1 @@
../../repository.vault
+7
View File
@@ -0,0 +1,7 @@
terraform {
backend "s3" {
bucket = "a13labs.infra"
key = "a13labs-iac.tfstate"
region = "us-east-1"
}
}
+52
View File
@@ -0,0 +1,52 @@
resource "scaleway_object_bucket" "infra_assets" {
name = "a13labs-infra-${var.bucket_suffix}"
project_id = var.scaleway_project_id
region = "fr-par"
}
resource "scaleway_object_bucket_policy" "policy" {
bucket = scaleway_object_bucket.infra_assets.name
policy = jsonencode({
Version = "2023-04-17",
Id = "AllowMachineDownload",
Statement = [
{
Effect = "Allow"
Action = [
"s3:ListBucket",
"s3:GetObject",
]
Principal = "*"
Resource = [
scaleway_object_bucket.infra_assets.name,
"${scaleway_object_bucket.infra_assets.name}/*",
]
Condition = {
IpAddress = {
"aws:SourceIp" = local.instance_ips
}
},
},
{
Effect = "Allow"
Action = [
"s3:*",
]
Principal = {
SCW = "user_id:${var.scaleway_user_id}"
}
Resource = [
scaleway_object_bucket.infra_assets.name,
"${scaleway_object_bucket.infra_assets.name}/*",
]
},
]
})
}
resource "scaleway_object" "encryption_key" {
bucket = scaleway_object_bucket.infra_assets.id
key = "keys/${data.contabo_instance.microk8s.mac_address}.key"
content_base64 = base64encode(var.encryption_key)
}
+5
View File
@@ -0,0 +1,5 @@
locals {
instance_ips = [
"${data.contabo_instance.microk8s.ip_config[0].v4[0].ip}/32",
]
}
+3
View File
@@ -0,0 +1,3 @@
data "contabo_instance" "microk8s" {
id = "201912751"
}
+52
View File
@@ -0,0 +1,52 @@
terraform {
required_version = "~>1.8"
required_providers {
random = {
source = "hashicorp/random"
version = "~>3.4"
}
null = {
source = "hashicorp/null"
version = "~>3.2"
}
external = {
source = "hashicorp/external"
version = "~>2.2"
}
time = {
source = "hashicorp/time"
version = "~>0.9"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~>2.18"
}
scaleway = {
source = "scaleway/scaleway"
version = "~>2.13"
}
contabo = {
source = "contabo/contabo"
version = "~>0.1"
}
}
}
provider "scaleway" {
zone = "fr-par-2"
region = "fr-par"
access_key = var.scaleway_access_key
secret_key = var.scaleway_secret_key
organization_id = var.scaleway_organization_id
}
# Configure your Contabo API credentials
provider "contabo" {
oauth2_client_id = var.contabo_client_id
oauth2_client_secret = var.contabo_client_secret
oauth2_user = var.contabo_api_user
oauth2_pass = var.contabo_api_password
}
+13
View File
@@ -0,0 +1,13 @@
AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=$AWS_SECRET_KEY
TF_VAR_scaleway_access_key=$SCALEWAY_ACCESS_KEY
TF_VAR_scaleway_secret_key=$SCALEWAY_SECRET_KEY
TF_VAR_scaleway_project_id=$SCALEWAY_PROJECT_ID
TF_VAR_scaleway_organization_id=$SCALEWAY_ORGANIZATION_ID
TF_VAR_scaleway_user_id=$SCALEWAY_USER_ID
TF_VAR_contabo_client_id=$CONTABO_CLIENT_ID
TF_VAR_contabo_client_secret=$CONTABO_CLIENT_SECRET
TF_VAR_contabo_api_password=$CONTABO_API_PASSWORD
TF_VAR_contabo_api_user=$CONTABO_USER_NAME
TF_VAR_bucket_suffix=$BUCKET_SUFFIX
TF_VAR_encryption_key=$ENCRYPT_KEY
View File
+65
View File
@@ -0,0 +1,65 @@
variable "scaleway_access_key" {
description = "Scaleway Access key"
type = string
sensitive = true
}
variable "scaleway_secret_key" {
description = "Scaleway Secret key"
type = string
sensitive = true
}
variable "scaleway_project_id" {
description = "Scaleway Project Id"
type = string
sensitive = true
}
variable "scaleway_organization_id" {
description = "Scaleway Organization Id"
type = string
sensitive = true
}
variable "scaleway_user_id" {
description = "Scaleway User Id"
type = string
sensitive = true
}
variable "contabo_client_id" {
description = "Contabo Client ID"
type = string
sensitive = true
}
variable "contabo_client_secret" {
description = "Contabo Client Secret"
type = string
sensitive = true
}
variable "contabo_api_password" {
description = "Contabo API Password"
type = string
sensitive = true
}
variable "contabo_api_user" {
description = "Contabo API User"
type = string
}
variable "encryption_key" {
description = "Encryption key for sensitive data"
type = string
sensitive = true
}
variable "bucket_suffix" {
description = "Suffix for bucket names"
type = string
sensitive = true
}