-
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.
Signed-off-by: gatici <[email protected]>
- Loading branch information
Showing
8 changed files
with
259 additions
and
4 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 |
---|---|---|
@@ -1,8 +1,54 @@ | ||
venv/ | ||
build/ | ||
*.charm | ||
.tox/ | ||
*.idea | ||
.vscode/ | ||
.coverage | ||
.tox/ | ||
venv/ | ||
build/ | ||
|
||
# Python | ||
**/venv/** | ||
*.pyc | ||
.python-version | ||
.mypy_cache/ | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# Charmcraft | ||
*.charm | ||
|
||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
.terraform.lock.hcl | ||
|
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,86 @@ | ||
# Contributing | ||
|
||
## Development environment | ||
|
||
### Prerequisites | ||
|
||
Make sure the following software and tools are installed in the development | ||
environment. | ||
|
||
- `microk8s` | ||
- `juju` | ||
- `terraform` | ||
|
||
### Prepare Development Environment | ||
|
||
Install Microk8s: | ||
|
||
```console | ||
sudo snap install microk8s --channel=1.27-strict/stable | ||
sudo usermod -a -G snap_microk8s $USER | ||
newgrp snap_microk8s | ||
``` | ||
|
||
Enable `storage` plugin for Microk8s: | ||
|
||
```console | ||
sudo microk8s enable hostpath-storage | ||
``` | ||
|
||
Install Juju: | ||
|
||
```console | ||
sudo snap install juju --channel=3.1/stable | ||
``` | ||
|
||
Install Terraform: | ||
|
||
```console | ||
sudo snap install --classic terraform | ||
``` | ||
|
||
Bootstrap the Juju Controller using Microk8s: | ||
|
||
```console | ||
juju bootstrap microk8s | ||
``` | ||
|
||
Add a Juju model: | ||
|
||
```console | ||
juju add model <model-name> | ||
```` | ||
|
||
### Terraform provider | ||
|
||
The Terraform module uses the Juju provider to provision Juju resources. Please refer to the [Juju provider documentation](https://registry.terraform.io/providers/juju/juju/latest/docs) for more information. | ||
|
||
A Terraform working directory needs to be initialized at the beginning. | ||
|
||
Initialise the provider: | ||
|
||
```console | ||
terraform init | ||
``` | ||
|
||
## Testing | ||
|
||
Terraform CLI provides various ways to do formatting and validation. | ||
|
||
Formats to a canonical format and style: | ||
|
||
```console | ||
terraform fmt | ||
``` | ||
|
||
Check the syntactical validation: | ||
|
||
```console | ||
terraform validate | ||
``` | ||
|
||
Preview the changes: | ||
|
||
```console | ||
terraform plan | ||
``` |
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,70 @@ | ||
# Mongodb-k8s Terraform Module | ||
|
||
This mongodb-k8s Terraform module aims to deploy the [mongodb-k8s charm](https://charmhub.io/mongodb-k8s?channel=6/edge) via Terraform. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
The following software and tools needs to be installed and should be running in the local environment. | ||
|
||
- `microk8s` | ||
- `juju 3.x` | ||
- `terrafom` | ||
|
||
### Deploy the Mongodb-k8s charm using Terraform | ||
|
||
Make sure that `storage` plugin is enabled for Microk8s: | ||
|
||
```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. | ||
|
||
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: | ||
|
||
```console | ||
terraform apply -auto-approve | ||
``` | ||
|
||
### Check the Output | ||
|
||
Run `juju switch <juju model>` to switch to the target Juju model and observe the status of the application. | ||
|
||
```console | ||
juju status | ||
``` | ||
|
||
### Clean up | ||
|
||
Remove the application: | ||
|
||
```console | ||
terraform destroy -auto-approve | ||
``` |
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,13 @@ | ||
resource "juju_application" "mongodb-k8s" { | ||
name = "mongodb-k8s" | ||
model = var.model_name | ||
|
||
charm { | ||
name = "mongodb-k8s" | ||
channel = var.channel | ||
base = "[email protected]" | ||
} | ||
config = var.mongo-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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "db_application_name" { | ||
description = "Name of the deployed application." | ||
value = juju_application.mongodb-k8s.name | ||
} |
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,11 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
terraform { | ||
required_providers { | ||
juju = { | ||
source = "juju/juju" | ||
version = "~> 0.10.1" | ||
} | ||
} | ||
} |
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,9 @@ | ||
# Mandatory Config Options | ||
model_name = "put your model-name here" | ||
|
||
# Optional Configuration | ||
channel = "put the charm channel here" | ||
mongo-config = { | ||
auto-delete = "put True to remove any relevant databases associated with the relation when a relation is removed" | ||
role = "put role config here as shard, config-server or replication" | ||
} |
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,16 @@ | ||
variable "model_name" { | ||
description = "Name of Juju model to deploy application to" | ||
type = string | ||
default = "" | ||
} | ||
|
||
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 = {} | ||
} |