Skip to content

Commit

Permalink
apply Gulsum's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Feb 9, 2024
1 parent cfa3ade commit a2db87c
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
59 changes: 59 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# MongoDB Operator Terraform module

This folder contains a base [Terraform][Terraform] module for the `mongodb-k8s` charm.

The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm deployment onto any Kubernetes environment managed by [Juju][Juju].

The base module is not intended to be deployed in separation (it is possible though), but should rather serve as a building block for higher level modules.

## Module structure

- **main.tf** - Defines the Juju application to be deployed.
- **variables.tf** - Allows customization of the deployment such as Juju model name, channel or application name and charm configuration.
- **output.tf** - Responsible for integrating the module with other Terraform modules, primarily by defining potential integration endpoints (charm integrations), but also by exposing the application name.
- **terraform.tf** - Defines the Terraform provider.

## Using mongodb-k8s base module in higher level modules

If you want to use `mongodb-operator` base module as part of your Terraform module, import it like shown below.

```text
module "mongodb-operator" {
source = "git::https://github.com/canonical/mongodb-operator.git//terraform"
model_name = "juju_model_name"
(Customize configuration variables here if needed)
}
```

Please see the link to customize the Grafana configuration variables if needed.

- [MongoDB configuration options][MongoDB configuration options]

Create the integrations, for instance:

```text
resource "juju_integration" "amf-db" {
model = var.model_name
application {
name = module.amf.app_name
endpoint = module.amf.database_endpoint
}
application {
name = module.mongodb.app_name
endpoint = module.mongodb.database_endpoint
}
}
```

Please check the available [integration pairs][integration pairs].

[Terraform]: https://www.terraform.io/
[Juju]: https://juju.is
[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest
[MongoDB configuration options]: https://charmhub.io/mongodb-k8s/configure?channel=6/edge
[integration pairs]: https://charmhub.io/mongodb-k8s/integrations?channel=6/edge
16 changes: 16 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "mongodb-k8s" {
name = var.app_name
model = var.model_name

charm {
name = "mongodb-k8s"
channel = var.channel
base = "[email protected]"
}
config = var.mongo-config
units = 1
trust = true
}
51 changes: 51 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

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

# Provided integration endpoints

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

output "obsolete_endpoint" {
description = "Name of the endpoint to provide the mongodb interface."
value = "obsolete"
}

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

output "config_server_endpoint" {
description = "Name of the endpoint to provide the shards interface."
value = "config-server"
}

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"
}
11 changes: 11 additions & 0 deletions terraform/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

terraform {
required_providers {
juju = {
source = "juju/juju"
version = "~> 0.10.1"
}
}
}
25 changes: 25 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

variable "model_name" {
description = "Name of Juju model to deploy application to"
type = string
default = ""
}

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

variable "channel" {
description = "The channel to use when deploying a charm"
type = string
default = "6/beta"
}

variable "mongo-config" {
description = "Additional configuration for the MongoDB"
default = {}
}

0 comments on commit a2db87c

Please sign in to comment.