Skip to content

Commit

Permalink
update to new way of using TF
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Dec 5, 2024
1 parent 7ab69b7 commit f2675c4
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 47 deletions.
42 changes: 32 additions & 10 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
resource "juju_application" "machine_mongodb" {
name = var.app_name
model = var.juju_model_name
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "mongodb" {

charm {
name = "mongodb"
channel = var.channel
revision = var.revision
base = var.base
}

storage_directives = {
mongodb = var.storage_size
}

config = var.config
model = var.model
name = var.app_name
units = var.units
constraints = var.constraints
config = var.config
}


# TODO: uncomment once final fixes have been added for:
# Error: juju/terraform-provider-juju#443, juju/terraform-provider-juju#182
# placement = join(",", var.machines)

endpoint_bindings = [
for k, v in var.endpoint_bindings : {
endpoint = k, space = v
}
]

storage_directives = var.storage

lifecycle {
precondition {
condition = length(var.machines) == 0 || length(var.machines) == var.units
error_message = "Machine count does not match unit count"
}
precondition {
condition = length(var.storage) == 0 || lookup(var.storage, "count", 0) <= 1
error_message = "Only one storage is supported"
}
}
}
Binary file added terraform/myplan
Binary file not shown.
53 changes: 41 additions & 12 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
output "application_name" {
value = juju_application.machine_mongodb.name
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

output "app_name" {
description = "Name of the deployed application."
value = juju_application.mongodb.name
}

# Provided integration endpoints

output "database_endpoint" {
description = "Name of the endpoint to provide the mongodb_client interface."
value = "database"
}

output "cos_agent_endpoint" {
description = "Name of the endpoint to provide the cos_agent interface."
value = "cos-agent"
}

output "provides" {
value = {
database = "database",
cos_agent = "cos-agent",
}
output "config_server_endpoint" {
description = "Name of the endpoint to provide the shards interface."
value = "config-server"
}

output "requires" {
value = {
certificates = "certificates"
s3_parameters = "s3-parameters"
}
output "cluster_endpoint" {
description = "Name of the endpoint to provide the config-server interface."
value = "cluster"
}

# Required integration endpoints

output "certificates_endpoint" {
description = "Name of the endpoint to provide the tls-certificates interface."
value = "certificates"
}

output "s3_credentials_endpoint" {
description = "Name of the endpoint to provide the s3 interface."
value = "s3-credentials"
}

output "sharding_endpoint" {
description = "Name of the endpoint to provide the shards interface."
value = "sharding"
}
59 changes: 37 additions & 22 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
variable "juju_model_name" {
description = "Juju model name"
type = string
}
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

variable "app_name" {
description = "Name of the application in the Juju model."
description = "Application name"
type = string
default = "mongodb"
}

variable "channel" {
description = "Charm channel to use when deploying"
description = "Charm channel"
type = string
default = "6/stable"
}

variable "revision" {
description = "Revision number to deploy charm"
type = number
default = null
}

variable "base" {
description = "Application base"
description = "Charm base (old name: series)"
type = string
default = "[email protected]"
}

variable "config" {
description = "Map of charm configuration options"
type = map(string)
default = {}
}

variable "model" {
description = "Model name"
type = string
}

variable "revision" {
description = "Charm revision"
type = number
default = null
}

variable "units" {
description = "Number of units to deploy"
description = "Charm units"
type = number
default = 1
default = 3
}

variable "constraints" {
description = "Juju constraints to apply for this application."
description = "String listing constraints for this application"
type = string
default = "arch=amd64"
}

variable "storage_size" {
description = "Storage size"
type = string
default = "10G"
variable "machines" {
description = "List of machines for placement"
type = list(string)
default = []
}

variable "config" {
description = "Application configuration. Details at https://charmhub.io/mongodb/configurations"
variable "storage" {
description = "Map of storage used by the application"
type = map(string)
default = {}
}

variable "endpoint_bindings" {
description = "Map of endpoint bindings"
type = map(string)
default = {}
}
9 changes: 6 additions & 3 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

terraform {
required_version = ">= 1.6.6"
required_version = ">= 1.6"
required_providers {
juju = {
source = "juju/juju"
version = ">= 0.14.0"
version = "~> 0.14.0"
}
}
}
}

0 comments on commit f2675c4

Please sign in to comment.