AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Tf public media buckets (#8324)
Swiftyf6eebcab6ede
diff --git a/autogpt_platform/infra/terraform/environments/dev.tfvars b/autogpt_platform/infra/terraform/environments/dev.tfvarsindex 3b868ea5c3..1f72c6d907 100644--- a/autogpt_platform/infra/terraform/environments/dev.tfvars+++ b/autogpt_platform/infra/terraform/environments/dev.tfvars@@ -97,4 +97,8 @@ role_bindings = {}pods_ip_cidr_range = "10.1.0.0/16"-services_ip_cidr_range = "10.2.0.0/20"\ No newline at end of file+services_ip_cidr_range = "10.2.0.0/20"++public_bucket_names = ["website-artifacts"]+standard_bucket_names = []+bucket_admins = ["[email protected]", "[email protected]"]\ No newline at end of filediff --git a/autogpt_platform/infra/terraform/environments/prod.tfvars b/autogpt_platform/infra/terraform/environments/prod.tfvarsindex 43f2ae63c1..e935138928 100644--- a/autogpt_platform/infra/terraform/environments/prod.tfvars+++ b/autogpt_platform/infra/terraform/environments/prod.tfvars@@ -97,4 +97,8 @@ role_bindings = {}pods_ip_cidr_range = "10.1.0.0/16"-services_ip_cidr_range = "10.2.0.0/20"\ No newline at end of file+services_ip_cidr_range = "10.2.0.0/20"++public_bucket_names = ["website-artifacts"]+standard_bucket_names = []+bucket_admins = ["[email protected]", "[email protected]"]\ No newline at end of filediff --git a/autogpt_platform/infra/terraform/main.tf b/autogpt_platform/infra/terraform/main.tfindex 495130b6a0..31049ed40c 100644--- a/autogpt_platform/infra/terraform/main.tf+++ b/autogpt_platform/infra/terraform/main.tf@@ -61,4 +61,14 @@ module "iam" {service_accounts = var.service_accountsworkload_identity_bindings = var.workload_identity_bindingsrole_bindings = var.role_bindings-}\ No newline at end of file+}++module "storage" {+ source = "./modules/storage"++ project_id = var.project_id+ region = var.region+ standard_bucket_names = var.standard_bucket_names+ public_bucket_names = var.public_bucket_names+ bucket_admins = var.bucket_admins+}diff --git a/autogpt_platform/infra/terraform/modules/storage/main.tf b/autogpt_platform/infra/terraform/modules/storage/main.tfnew file mode 100644index 0000000000..a8a103a0df--- /dev/null+++ b/autogpt_platform/infra/terraform/modules/storage/main.tf@@ -0,0 +1,64 @@++# Public Buckets+resource "google_storage_bucket" "public_buckets" {+ for_each = toset(var.public_bucket_names)+ name = "${var.project_id}-${each.value}"+ location = var.region+ force_destroy = true++ uniform_bucket_level_access = true++ cors {+ origin = ["*"]+ method = ["GET", "HEAD", "OPTIONS"]+ response_header = ["*"]+ max_age_seconds = 3600+ }+}++resource "google_storage_bucket_iam_policy" "public_access" {+ for_each = google_storage_bucket.public_buckets++ bucket = each.value.name+ policy_data = jsonencode({+ bindings = [+ {+ role = "roles/storage.objectViewer"+ members = ["allUsers"]+ },+ {+ role = "roles/storage.admin"+ members = [for admin in var.bucket_admins : "group:${admin}"]+ }+ ]+ })+}++# Standard Buckets, with default permissions+resource "google_storage_bucket" "standard_buckets" {+ for_each = toset(var.standard_bucket_names)+ name = "${var.project_id}-${each.value}"+ location = var.region+ force_destroy = true++ uniform_bucket_level_access = true++ versioning {+ enabled = true+ }++}++resource "google_storage_bucket_iam_member" "standard_access" {+ for_each = {+ for pair in setproduct(keys(google_storage_bucket.standard_buckets), ["[email protected]", "[email protected]"]) :+ "${pair[0]}-${pair[1]}" => {+ bucket = google_storage_bucket.standard_buckets[pair[0]].name+ member = "group:${pair[1]}"+ }+ }++ bucket = each.value.bucket+ role = "roles/storage.objectAdmin"+ member = each.value.member+}diff --git a/autogpt_platform/infra/terraform/modules/storage/outputs.tf b/autogpt_platform/infra/terraform/modules/storage/outputs.tfnew file mode 100644index 0000000000..d2d0f527dc--- /dev/null+++ b/autogpt_platform/infra/terraform/modules/storage/outputs.tf@@ -0,0 +1,19 @@+output "public_bucket_names" {+ description = "The names of the created website artifacts buckets"+ value = { for k, v in google_storage_bucket.public_buckets : k => v.name }+}++output "public_bucket_urls" {+ description = "The URLs of the created website artifacts buckets"+ value = { for k, v in google_storage_bucket.public_buckets : k => v.url }+}++output "standard_bucket_names" {+ description = "The names of the created standard buckets"+ value = { for k, v in google_storage_bucket.standard_buckets : k => v.name }+}++output "standard_bucket_urls" {+ description = "The URLs of the created standard buckets"+ value = { for k, v in google_storage_bucket.standard_buckets : k => v.url }+}diff --git a/autogpt_platform/infra/terraform/modules/storage/variables.tf b/autogpt_platform/infra/terraform/modules/storage/variables.tfnew file mode 100644index 0000000000..57d9abb094--- /dev/null+++ b/autogpt_platform/infra/terraform/modules/storage/variables.tf@@ -0,0 +1,27 @@+variable "project_id" {+ description = "The ID of the project"+ type = string+}++variable "region" {+ description = "The region where the bucket will be created"+ type = string+}++variable "public_bucket_names" {+ description = "List of bucket names that should be publicly accessible"+ type = list(string)+ default = []+}++variable "standard_bucket_names" {+ description = "List of bucket names that should be publicly accessible"+ type = list(string)+ default = []+}++variable "bucket_admins" {+ description = "List of groups that should be admins of the buckets"+ type = list(string)+ default = ["[email protected]", "[email protected]"]+}diff --git a/autogpt_platform/infra/terraform/variables.tf b/autogpt_platform/infra/terraform/variables.tfindex 76da68cce5..1afd9509fc 100644--- a/autogpt_platform/infra/terraform/variables.tf+++ b/autogpt_platform/infra/terraform/variables.tf@@ -110,4 +110,23 @@ variable "services_ip_cidr_range" {description = "The IP address range for services"type = stringdefault = "10.2.0.0/20"-}\ No newline at end of file+}++variable "public_bucket_names" {+ description = "List of bucket names that should be publicly accessible"+ type = list(string)+ default = []+}++variable "standard_bucket_names" {+ description = "List of bucket names that should be publicly accessible"+ type = list(string)+ default = []+}++variable "bucket_admins" {+ description = "List of groups that should be admins of the buckets"+ type = list(string)+ default = ["[email protected]", "[email protected]"]+}+