-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Github workflow for the Terraform checks
Signed-off-by: gatici <[email protected]>
- Loading branch information
Showing
8 changed files
with
119 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
name: Check Terraform Module | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.tf' | ||
|
||
jobs: | ||
check-terraform-module: | ||
name: Check Terraform Module | ||
uses: canonical/data-platform-workflows/.github/workflows/terraform.yaml@main | ||
secrets: inherit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,54 @@ | ||
# Mongodb-k8s Terraform Module | ||
# MongoDB Operator Terraform module | ||
|
||
This mongodb-k8s Terraform module aims to deploy the [mongodb-k8s charm](https://charmhub.io/mongodb-k8s?channel=6/edge) via Terraform. | ||
This folder contains a base [Terraform][Terraform] module for the `mongodb-k8s` charm. | ||
|
||
## Getting Started | ||
The module uses the [Terraform Juju provider][Terraform Juju provider] to model the charm deployment onto any Kubernetes environment managed by [Juju][Juju]. | ||
|
||
### Prerequisites | ||
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. | ||
|
||
The following software and tools needs to be installed and should be running in the local environment. | ||
## Module structure | ||
|
||
- `microk8s` | ||
- `juju 3.x` | ||
- `terrafom` | ||
- **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. | ||
|
||
### Deploy the Mongodb-k8s charm using Terraform | ||
## Using mongodb-k8s base module in higher level modules | ||
|
||
Make sure that `storage` plugin is enabled for Microk8s: | ||
If you want to use `mongodb-operator` base module as part of your Terraform module, import it like shown below. | ||
|
||
```console | ||
sudo microk8s enable hostpath-storage | ||
``` | ||
|
||
Add a Juju model: | ||
|
||
```console | ||
juju add model <model-name> | ||
``` | ||
|
||
Initialise the provider: | ||
|
||
```console | ||
terraform init | ||
``` | ||
|
||
Customize the configuration inputs under `terraform.tfvars` file according to requirement. | ||
```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) | ||
Replace the values in the `terraform.tfvars` file: | ||
|
||
```yaml | ||
# Mandatory Config Options | ||
model_name = "put your model-name here" | ||
``` | ||
|
||
Run Terraform Plan by providing var-file: | ||
|
||
```console | ||
terraform plan -var-file="terraform.tfvars" | ||
} | ||
``` | ||
|
||
Deploy the resources, skip the approval: | ||
Create the integrations, for instance: | ||
|
||
```console | ||
terraform apply -auto-approve | ||
``` | ||
|
||
### Check the Output | ||
```text | ||
resource "juju_integration" "amf-db" { | ||
model = var.model_name | ||
Run `juju switch <juju model>` to switch to the target Juju model and observe the status of the application. | ||
application { | ||
name = module.amf.app_name | ||
endpoint = module.amf.database_endpoint | ||
} | ||
```console | ||
juju status | ||
application { | ||
name = module.mongodb.app_name | ||
endpoint = module.mongodb.database_endpoint | ||
} | ||
} | ||
``` | ||
|
||
### Clean up | ||
Please check the available [integration pairs][integration pairs]. | ||
|
||
Remove the application: | ||
|
||
```console | ||
terraform destroy -auto-approve | ||
``` | ||
[Terraform]: https://www.terraform.io/ | ||
[Juju]: https://juju.is | ||
[Terraform Juju provider]: https://registry.terraform.io/providers/juju/juju/latest | ||
[integration pairs]: https://charmhub.io/mongodb-k8s/integrations?channel=6/edge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
resource "juju_application" "mongodb-k8s" { | ||
name = "mongodb-k8s" | ||
name = var.app_name | ||
model = var.model_name | ||
|
||
charm { | ||
name = "mongodb-k8s" | ||
channel = var.channel | ||
base = "[email protected]" | ||
} | ||
config = var.mongo-config | ||
config = var.config | ||
units = 1 | ||
trust = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,51 @@ | ||
output "db_application_name" { | ||
# 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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
# 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 " | ||
description = "The channel to use when deploying a charm" | ||
type = string | ||
default = "6/beta" | ||
} | ||
|
||
variable "mongo-config" { | ||
description = "Additional configuration for the MongoDB" | ||
variable "config" { | ||
description = "Additional configuration for the MongoDB. Details about available options can be found at https://charmhub.io/mongodb-k8s/configure?channel=6/edge." | ||
type = map(string) | ||
default = {} | ||
} |