From 55d47201798c06d2d9967046790f4606cdaa85ea Mon Sep 17 00:00:00 2001 From: Paulo Machado Date: Tue, 15 Oct 2024 09:34:08 -0300 Subject: [PATCH] tf module on charm (#643) --- terraform/main.tf | 19 +++++++++++++++ terraform/outputs.tf | 18 +++++++++++++++ terraform/variables.tf | 52 ++++++++++++++++++++++++++++++++++++++++++ terraform/versions.tf | 9 ++++++++ 4 files changed, 98 insertions(+) create mode 100644 terraform/main.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/variables.tf create mode 100644 terraform/versions.tf diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000000..e55420a960 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,19 @@ +resource "juju_application" "machine_postgresql" { + name = var.app_name + model = var.juju_model_name + + charm { + name = "postgresql" + channel = var.channel + revision = var.revision + base = var.base + } + + storage_directives = { + pgdata = var.storage_size + } + + units = var.units + constraints = var.constraints + config = var.config +} diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000000..52f1981f24 --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,18 @@ +output "application_name" { + value = juju_application.machine_postgresql.name +} + + +output "provides" { + value = { + database = "database", + cos_agent = "cos-agent", + } +} + +output "requires" { + value = { + certificates = "certificates" + s3_parameters = "s3-parameters" + } +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000000..ede475f37a --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,52 @@ +variable "juju_model_name" { + description = "Juju model name" + type = string +} + +variable "app_name" { + description = "Name of the application in the Juju model." + type = string + default = "postgresql" +} + +variable "channel" { + description = "Charm channel to use when deploying" + type = string + default = "14/stable" +} + +variable "revision" { + description = "Revision number to deploy charm" + type = number + default = null +} + +variable "base" { + description = "Application base" + type = string + default = "ubuntu@22.04" +} + +variable "units" { + description = "Number of units to deploy" + type = number + default = 1 +} + +variable "constraints" { + description = "Juju constraints to apply for this application." + type = string + default = "arch=amd64" +} + +variable "storage_size" { + description = "Storage size" + type = string + default = "10G" +} + +variable "config" { + description = "Application configuration. Details at https://charmhub.io/postgresql/configurations" + type = map(string) + default = {} +} diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000000..3586261576 --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.6.6" + required_providers { + juju = { + source = "juju/juju" + version = ">= 0.14.0" + } + } +}