generated from canonical/is-charms-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inital pass at adding terraform for the k8s charms
- Loading branch information
1 parent
08a744d
commit c9a8369
Showing
10 changed files
with
348 additions
and
0 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,61 @@ | ||
# Terraform module for k8s | ||
|
||
This is a Terraform module facilitating the deployment of the k8s charm, using the [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). | ||
Check warning on line 3 in charms/worker/k8s/terraform/README.md GitHub Actions / unit-tests / Style checker
|
||
|
||
## Requirements | ||
This module requires a `juju` model to be available. Refer to the [usage section](#usage) below for more details. | ||
|
||
## API | ||
Check warning on line 8 in charms/worker/k8s/terraform/README.md GitHub Actions / unit-tests / Style checker
|
||
|
||
### 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 | | ||
| `config`| map(string) | Map of the charm configuration options | False | | ||
| `constriants` | string | Juju constraits to apply for this aplication | False | | ||
| `model`| 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 | | ||
| `series` | string | Ubuntu series to deploy the carm onto | False | | ||
| `units` | number | Number of units to deploy | 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" "testing" { | ||
name = canonical-k8s | ||
} | ||
module "k8s" { | ||
source = "<path-to-this-directory>" | ||
model_name = juju_model.testing.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" "testing" { | ||
name = var.model_name | ||
} | ||
module "k8s" { | ||
source = "<path-to-this-directory>" | ||
model_name = data.juju_model.testing.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,19 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
resource "juju_application" "k8s" { | ||
name = var.app_name | ||
model = var.model | ||
|
||
charm { | ||
name = "k8s" | ||
channel = var.channel | ||
revision = var.revision | ||
series = var.series | ||
} | ||
|
||
config = var.config | ||
constraints = var.constraints | ||
units = var.units | ||
resources = var.resources | ||
} |
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,24 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
output "app_name" { | ||
description = "Name of the deployed application." | ||
value = juju_application.k8s.name | ||
} | ||
|
||
output "requires" { | ||
value = { | ||
aws = "aws-integration" | ||
azure = "azure-integration" | ||
cluster = "k8s-cluster" | ||
cos_tokens = "cos-k8s-tokens" | ||
containerd = "containerd" | ||
gcp = "gcp-integration" | ||
} | ||
} | ||
|
||
output "provides" { | ||
value = { | ||
cos_agent = "cos_agent" | ||
} | ||
} |
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,61 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
variable "app_name" { | ||
description = "Name of the application in the Juju model." | ||
type = string | ||
default = "k8s" | ||
} | ||
|
||
variable "channel" { | ||
description = "The channel to use when deploying a charm." | ||
type = string | ||
default = "1.30/edge" | ||
} | ||
|
||
variable "config" { | ||
description = "Application config. Details about available options can be found at https://charmhub.io/k8s/configurations." | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "constraints" { | ||
description = "Juju constraints to apply for this application." | ||
type = string | ||
default = "arch=amd64" | ||
} | ||
|
||
variable "model" { | ||
description = "Reference to a `juju_model`." | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "resources" { | ||
description = "Resources to use with the application. Details about available options can be found at https://charmhub.io/k8s/configurations." | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "revision" { | ||
description = "Revision number of the charm" | ||
type = number | ||
default = null | ||
} | ||
|
||
variable "series" { | ||
description = "Ubuntu series to deploy the charm onto" | ||
type = string | ||
default = "24.04" | ||
|
||
validation { | ||
condition = contains(["20.04", "22.04", "24.04"], var.series) | ||
error_message = "Series must be one of 20.04, 22.04, 24.04" | ||
} | ||
} | ||
|
||
variable "units" { | ||
description = "Number of units to deploy" | ||
type = number | ||
default = 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 @@ | ||
terraform { | ||
required_version = ">= 1.6" | ||
required_providers { | ||
juju = { | ||
source = "juju/juju" | ||
version = "~> 0.14.0" | ||
} | ||
} | ||
} |
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,61 @@ | ||
# Terraform module for k8s-worker | ||
|
||
This is a Terraform module facilitating the deployment of the k8s-worker charm, using the [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). | ||
Check warning on line 3 in charms/worker/terraform/README.md GitHub Actions / unit-tests / Style checker
|
||
|
||
## Requirements | ||
This module requires a `juju` model to be available. Refer to the [usage section](#usage) below for more details. | ||
|
||
## API | ||
Check warning on line 8 in charms/worker/terraform/README.md GitHub Actions / unit-tests / Style checker
|
||
|
||
### 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 | | ||
| `config`| map(string) | Map of the charm configuration options | False | | ||
| `constriants` | string | Juju constraits to apply for this aplication | False | | ||
| `model`| 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 | | ||
| `series` | string | Ubuntu series to deploy the carm onto | False | | ||
| `units` | number | Number of units to deploy | 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" "testing" { | ||
name = canonical-k8s | ||
} | ||
module "k8s_worker" { | ||
source = "<path-to-this-directory>" | ||
model_name = juju_model.testing.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" "testing" { | ||
name = var.model_name | ||
} | ||
module "k8s_worker" { | ||
source = "<path-to-this-directory>" | ||
model_name = data.juju_model.testing.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,19 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
resource "juju_application" "k8s_worker" { | ||
name = var.app_name | ||
model = var.model | ||
|
||
charm { | ||
name = "k8s-worker" | ||
channel = var.channel | ||
revision = var.revision | ||
series = var.series | ||
} | ||
|
||
config = var.config | ||
constraints = var.constraints | ||
units = var.units | ||
resources = var.resources | ||
} |
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,24 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
output "app_name" { | ||
description = "Name of the deployed application." | ||
value = juju_application.k8s_worker.name | ||
} | ||
|
||
output "requires" { | ||
value = { | ||
aws = "aws-integration" | ||
azure = "azure-integration" | ||
cluster = "k8s-cluster" | ||
cos_tokens = "cos-k8s-tokens" | ||
containerd = "containerd" | ||
gcp = "gcp-integration" | ||
} | ||
} | ||
|
||
output "provides" { | ||
value = { | ||
cos_agent = "cos_agent" | ||
} | ||
} |
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,61 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
variable "app_name" { | ||
description = "Name of the application in the Juju model." | ||
type = string | ||
default = "k8s-worker" | ||
} | ||
|
||
variable "channel" { | ||
description = "The channel to use when deploying a charm." | ||
type = string | ||
default = "1.30/edge" | ||
} | ||
|
||
variable "config" { | ||
description = "Application config. Details about available options can be found at https://charmhub.io/k8s-worker/configurations." | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "constraints" { | ||
description = "Juju constraints to apply for this application." | ||
type = string | ||
default = "arch=amd64" | ||
} | ||
|
||
variable "model" { | ||
description = "Reference to a `juju_model`." | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "resources" { | ||
description = "Resources to use with the application. Details about available options can be found at https://charmhub.io/k8s-worker/configurations." | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "revision" { | ||
description = "Revision number of the charm" | ||
type = number | ||
default = null | ||
} | ||
|
||
variable "series" { | ||
description = "Ubuntu series to deploy the charm onto" | ||
type = string | ||
default = "24.04" | ||
|
||
validation { | ||
condition = contains(["20.04", "22.04", "24.04"], var.series) | ||
error_message = "Series must be one of 20.04, 22.04, 24.04" | ||
} | ||
} | ||
|
||
variable "units" { | ||
description = "Number of units to deploy" | ||
type = number | ||
default = 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 @@ | ||
terraform { | ||
required_version = ">= 1.6" | ||
required_providers { | ||
juju = { | ||
source = "juju/juju" | ||
version = "~> 0.14.0" | ||
} | ||
} | ||
} |