Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ module "mimir_worker" {

# -------------- # S3-integrator --------------

locals {
deploy_s3 = var.s3_endpoint != null
}

resource "juju_secret" "mimir_s3_credentials_secret" {
count = local.deploy_s3 ? 1 : 0
model_uuid = var.model_uuid
name = "mimir_s3_credentials"
value = {
Expand All @@ -45,18 +50,20 @@ resource "juju_secret" "mimir_s3_credentials_secret" {
}

resource "juju_access_secret" "mimir_s3_secret_access" {
count = local.deploy_s3 ? 1 : 0
model_uuid = var.model_uuid
applications = [
juju_application.s3_integrator.name
juju_application.s3_integrator[0].name
]
secret_id = juju_secret.mimir_s3_credentials_secret.secret_id
secret_id = juju_secret.mimir_s3_credentials_secret[0].secret_id
}

resource "juju_application" "s3_integrator" {
count = local.deploy_s3 ? 1 : 0
config = merge({
endpoint = var.s3_endpoint
bucket = var.s3_bucket
credentials = "secret:${juju_secret.mimir_s3_credentials_secret.secret_id}"
credentials = "secret:${juju_secret.mimir_s3_credentials_secret[0].secret_id}"
}, var.s3_integrator_config)
constraints = var.s3_integrator_constraints
model_uuid = var.model_uuid
Expand All @@ -75,9 +82,10 @@ resource "juju_application" "s3_integrator" {
# -------------- # Integrations --------------

resource "juju_integration" "coordinator_to_s3_integrator" {
count = local.deploy_s3 ? 1 : 0
model_uuid = var.model_uuid
application {
name = juju_application.s3_integrator.name
name = juju_application.s3_integrator[0].name
endpoint = "s3-credentials"
}

Expand Down
4 changes: 2 additions & 2 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "app_names" {
value = merge(
{
mimir_s3_integrator = juju_application.s3_integrator.name,
mimir_coordinator = module.mimir_coordinator.app_name,
mimir_coordinator = module.mimir_coordinator.app_name,
},
local.deploy_s3 ? { mimir_s3_integrator = juju_application.s3_integrator[0].name } : {},
{ for k, v in module.mimir_worker : "mimir_${k}" => v.app_name }
)
description = "All application names which make up this product module"
Expand Down
17 changes: 14 additions & 3 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,30 @@ variable "s3_bucket" {
}

variable "s3_access_key" {
description = "S3 access-key credential"
description = "S3 access-key credential. Set to null (along with s3_endpoint and s3_secret_key) to skip deploying the S3 integrator."
type = string
default = null
}

variable "s3_secret_key" {
description = "S3 secret-key credential"
description = "S3 secret-key credential. Set to null (along with s3_endpoint and s3_access_key) to skip deploying the S3 integrator."
type = string
sensitive = true
default = null
}

variable "s3_endpoint" {
description = "S3 endpoint"
description = "S3 endpoint. When null, the S3 integrator is not deployed and the caller must handle storage integration externally."
type = string
default = null

validation {
condition = (
(var.s3_endpoint == null && var.s3_access_key == null && var.s3_secret_key == null) ||
(var.s3_endpoint != null && var.s3_access_key != null && var.s3_secret_key != null)
)
error_message = "s3_endpoint, s3_access_key, and s3_secret_key must all be set or all be null."
}
}

# -------------- # Workers --------------
Expand Down