-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPE-5867] Add terraform module #134
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2e5e77a
Add terraform module
phvalguima 50251e4
Extend size to 3x units per deployment
phvalguima 6790019
Fix the typo in the simple_deployment.tf
phvalguima bb882bd
Fix simple deployment and variables to 1x clusters
phvalguima b1e76f9
Update following opensearch charm TF
phvalguima 1f39a22
Update main.tf
phvalguima 4b59abe
Update variables.tf
phvalguima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 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,90 @@ | ||
# Terraform module for opensearch-dashboards-operator | ||
|
||
This is a Terraform module facilitating the deployment of the OpenSearch charm with [Terraform juju provider](https://github.com/juju/terraform-provider-juju/). For more information, refer to the provider [documentation](https://registry.terraform.io/providers/juju/juju/latest/docs). | ||
|
||
## Requirements | ||
This module requires a `juju` model to be available. Refer to the [usage section](#usage) below for more details. | ||
|
||
## API | ||
|
||
### Inputs | ||
The module offers the following configurable inputs: | ||
|
||
| Name | Type | Description | Required | | ||
| - | - | - | - | | ||
| `app_name`| string | Application name | False | | ||
| `channel`| string | Channel that the charm is deployed from | False | | ||
| `base`| string | The series to be used for this charm | False | | ||
| `config`| map(string) | Map of the charm configuration options | False | | ||
| `model_name`| string | Name of the model that the charm is deployed on | True | | ||
| `resources`| map(string) | Map of the charm resources | False | | ||
| `revision`| number | Revision number of the charm name | False | | ||
| `units`| number | Number of units to be deployed | False | | ||
| `constraints`| string | Machine constraints for the charm | False | | ||
|
||
|
||
### Outputs | ||
Upon applied, the module exports the following outputs: | ||
|
||
| Name | Description | | ||
| - | - | | ||
| `app_name`| Application name | | ||
| `provides`| Map of `provides` endpoints | | ||
| `requires`| Map of `requires` endpoints | | ||
|
||
## Usage | ||
|
||
This module is intended to be used as part of a higher-level module. When defining one, users should ensure that Terraform is aware of the `juju_model` dependency of the charm module. There are two options to do so when creating a high-level module: | ||
|
||
### Define a `juju_model` resource | ||
Define a `juju_model` resource and pass to the `model_name` input a reference to the `juju_model` resource's name. For example: | ||
|
||
``` | ||
resource "juju_model" "opensearch" { | ||
name = opensearch | ||
} | ||
|
||
module "opensearch-dashboards" { | ||
source = "<path-to-this-directory>" | ||
model_name = juju_model.opensearch.name | ||
} | ||
``` | ||
|
||
### Define a `data` source | ||
Define a `data` source and pass to the `model_name` input a reference to the `data.juju_model` resource's name. This will enable Terraform to look for a `juju_model` resource with a name attribute equal to the one provided, and apply only if this is present. Otherwise, it will fail before applying anything. | ||
|
||
``` | ||
data "juju_model" "opensearch" { | ||
name = var.model_name | ||
} | ||
|
||
module "opensearch-dashboards" { | ||
source = "<path-to-this-directory>" | ||
model_name = data.juju_model.opensearch.name | ||
} | ||
``` | ||
|
||
### Deploy OpenSearch Module and Relate | ||
|
||
Follow the description in: https://github.com/canonical/opensearch-operator/, in the `terraform` folder. Deploy an opensearch | ||
cluster and relate both of them together: | ||
|
||
``` | ||
module "opensearch" { | ||
... | ||
} | ||
|
||
resource "juju_integration" "opensearch-and-dashboard" { | ||
model = juju_model.opensearch.name | ||
|
||
application { | ||
name = module.opensearch.app_name | ||
endpoint = module.opensearch.opensearch_client_endpoint | ||
} | ||
|
||
application { | ||
name = module.opensearch-dashboards.app_name | ||
endpoint = module.opensearch-dashboards.opensearch_client_endpoint | ||
} | ||
} | ||
``` |
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,35 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
resource "juju_application" "opensearch-dashboards" { | ||
|
||
charm { | ||
name = "opensearch-dashboards" | ||
channel = var.channel | ||
revision = var.revision | ||
base = var.base | ||
} | ||
config = var.config | ||
model = var.model | ||
name = var.app_name | ||
units = var.units | ||
constraints = var.constraints | ||
|
||
|
||
# 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 | ||
} | ||
] | ||
|
||
lifecycle { | ||
precondition { | ||
condition = length(var.machines) == 0 || length(var.machines) == var.units | ||
error_message = "Machine count does not match unit count" | ||
} | ||
} | ||
} |
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,26 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
output "app_name" { | ||
description = "Name of the deployed application." | ||
value = juju_application.opensearch-dashboards.name | ||
} | ||
|
||
# Required integration endpoints | ||
|
||
output "certificates_endpoint" { | ||
description = "Name of the endpoint used to integrate with the TLS certificates provider." | ||
value = "certificates" | ||
} | ||
|
||
output "opensearch_client_endpoint" { | ||
description = "Name of the endpoint opensearch-client endpoint." | ||
value = "opensearch-client" | ||
} | ||
|
||
# Provided integration endpoints | ||
|
||
output "cos_agent_endpoint" { | ||
description = "Name of the endpoint used to provide COS agent integration." | ||
value = "cos-agent-endpoint" | ||
} |
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,18 @@ | ||
resource "null_resource" "preamble" { | ||
provisioner "local-exec" { | ||
command = <<-EOT | ||
sudo snap install juju-wait --classic || true | ||
sudo sysctl -w vm.max_map_count=262144 vm.swappiness=0 net.ipv4.tcp_retries2=5 | ||
EOT | ||
} | ||
|
||
} | ||
|
||
resource "juju_application" "self-signed-certificates" { | ||
charm { | ||
name = "self-signed-certificates" | ||
channel = "latest/stable" | ||
} | ||
model = var.model_name | ||
depends_on = [null_resource.preamble] | ||
} |
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 @@ | ||
terraform { | ||
required_providers { | ||
juju = { | ||
source = "juju/juju" | ||
version = "~> 0.14.0" | ||
} | ||
http = { | ||
source = "hashicorp/http" | ||
version = "~> 3.4.5" | ||
} | ||
external = { | ||
source = "hashicorp/external" | ||
version = "~> 2.3.4" | ||
} | ||
} | ||
} |
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,89 @@ | ||
module "opensearch-dashboards" { | ||
source = "../" | ||
app_name = var.app_name | ||
model = var.model_name | ||
units = var.simple_opensearch_dashboards_units | ||
|
||
channel = "2/edge" | ||
|
||
depends_on = [juju_application.self-signed-certificates] | ||
} | ||
|
||
module "opensearch" { | ||
source = "git::https://github.com/canonical/opensearch-operator//terraform?ref=2/edge" | ||
app_name = "opensearch" | ||
model = var.model_name | ||
units = var.simple_opensearch_units | ||
config = { | ||
profile = "testing" | ||
} | ||
|
||
channel = "2/edge" | ||
|
||
depends_on = [juju_application.self-signed-certificates] | ||
} | ||
|
||
resource "juju_integration" "dashboards_opensearch-integration" { | ||
model = var.model_name | ||
|
||
application { | ||
name = module.opensearch-dashboards.app_name | ||
endpoint = module.opensearch-dashboards.opensearch_client_endpoint | ||
} | ||
application { | ||
name = module.opensearch.app_name | ||
endpoint = module.opensearch.opensearch_client_endpoint | ||
} | ||
depends_on = [ | ||
module.opensearch-dashboards, | ||
module.opensearch | ||
] | ||
|
||
} | ||
|
||
resource "juju_integration" "simple_deployment_tls-operator_opensearch-dashboards-integration" { | ||
model = var.model_name | ||
|
||
application { | ||
name = juju_application.self-signed-certificates.name | ||
} | ||
application { | ||
name = module.opensearch.app_name | ||
} | ||
depends_on = [ | ||
juju_application.self-signed-certificates, | ||
module.opensearch | ||
] | ||
|
||
} | ||
|
||
|
||
resource "juju_integration" "simple_deployment_tls-operator_opensearch-integration" { | ||
model = var.model_name | ||
|
||
application { | ||
name = juju_application.self-signed-certificates.name | ||
} | ||
application { | ||
name = module.opensearch-dashboards.app_name | ||
} | ||
depends_on = [ | ||
juju_application.self-signed-certificates, | ||
module.opensearch | ||
] | ||
|
||
} | ||
|
||
resource "null_resource" "simple_deployment_juju_wait_deployment" { | ||
provisioner "local-exec" { | ||
command = <<-EOT | ||
juju-wait -v --model ${var.model_name} | ||
EOT | ||
} | ||
|
||
depends_on = [ | ||
juju_integration.simple_deployment_tls-operator_opensearch-integration, | ||
juju_integration.dashboards_opensearch-integration, | ||
juju_integration.simple_deployment_tls-operator_opensearch-dashboards-integration, | ||
] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: This is a really tasteful check 👍🏾