Skip to content
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

feat: add variables to set AppProject, labels and destination cluster #16

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module "longhorn" {
}]

dependency_ids = {
argocd = module.argocd_bootstrap.id
argocd = module.argocd_bootstrap.id
traefik = module.traefik.id
cert-manager = module.cert-manager.id
keycloak = module.keycloak.id
Expand Down Expand Up @@ -216,11 +216,11 @@ The following providers are used by this module:

- [[provider_random]] <<provider_random,random>> (>= 3)

- [[provider_null]] <<provider_null,null>>
- [[provider_utils]] <<provider_utils,utils>> (>= 1)

- [[provider_argocd]] <<provider_argocd,argocd>> (>= 5)

- [[provider_utils]] <<provider_utils,utils>> (>= 1)
- [[provider_null]] <<provider_null,null>>

=== Resources

Expand Down Expand Up @@ -269,6 +269,30 @@ Type: `string`

Default: `"argocd"`

==== [[input_argocd_project]] <<input_argocd_project,argocd_project>>

Description: Name of the Argo CD AppProject where the Application should be created. If not set, the Application will be created in a new AppProject only for this Application.

Type: `string`

Default: `null`

==== [[input_argocd_labels]] <<input_argocd_labels,argocd_labels>>

Description: Labels to attach to the Argo CD Application resource.

Type: `map(string)`

Default: `{}`

==== [[input_destination_cluster]] <<input_destination_cluster,destination_cluster>>

Description: Destination cluster where the application should be deployed.

Type: `string`

Default: `"in-cluster"`

==== [[input_target_revision]] <<input_target_revision,target_revision>>

Description: Override of target revision of the application chart.
Expand Down Expand Up @@ -564,6 +588,24 @@ Description: ID to pass other modules in order to refer to this module as a depe
|`"argocd"`
|no

|[[input_argocd_project]] <<input_argocd_project,argocd_project>>
|Name of the Argo CD AppProject where the Application should be created. If not set, the Application will be created in a new AppProject only for this Application.
|`string`
|`null`
|no

|[[input_argocd_labels]] <<input_argocd_labels,argocd_labels>>
|Labels to attach to the Argo CD Application resource.
|`map(string)`
|`{}`
|no

|[[input_destination_cluster]] <<input_destination_cluster,destination_cluster>>
|Destination cluster where the application should be deployed.
|`string`
|`"in-cluster"`
|no

|[[input_target_revision]] <<input_target_revision,target_revision>>
|Override of target revision of the application chart.
|`string`
Expand Down
6 changes: 3 additions & 3 deletions charts/longhorn/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ apiVersion: "v2"
name: "longhorn"
version: "0"
dependencies:
- name: "longhorn"
version: "1.4.2"
repository: "https://charts.longhorn.io"
- name: "longhorn"
version: "1.4.2"
repository: "https://charts.longhorn.io"
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ locals {
} : null)
numberOfReplicas = var.replica_count
oidc = var.oidc != null ? {
oauth2_proxy_image = "quay.io/oauth2-proxy/oauth2-proxy:v7.4.0"
oauth2_proxy_image = "quay.io/oauth2-proxy/oauth2-proxy:v7.5.0"
issuer_url = var.oidc.issuer_url
redirect_url = format("https://%s/oauth2/callback", local.domain_full)
client_id = var.oidc.client_id
Expand Down
18 changes: 12 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ resource "null_resource" "dependencies" {
}

resource "argocd_project" "this" {
count = var.argocd_project == null ? 1 : 0

metadata {
name = "longhorn"
name = var.destination_cluster != "in-cluster" ? "longhorn-${var.destination_cluster}" : "longhorn"
namespace = var.argocd_namespace
annotations = {
"devops-stack.io/argocd_namespace" = var.argocd_namespace
}
}

spec {
description = "Longhorn application project"
description = "Longhorn application project for cluster ${var.destination_cluster}"
source_repos = ["https://github.com/camptocamp/devops-stack-module-longhorn.git"]

destination {
name = "in-cluster"
name = var.destination_cluster
namespace = var.namespace
}

Expand All @@ -37,8 +39,12 @@ data "utils_deep_merge_yaml" "values" {

resource "argocd_application" "this" {
metadata {
name = "longhorn"
name = var.destination_cluster != "in-cluster" ? "longhorn-${var.destination_cluster}" : "longhorn"
namespace = var.argocd_namespace
labels = merge({
"application" = "longhorn"
"cluster" = var.destination_cluster
}, var.argocd_labels)
}

timeouts {
Expand All @@ -49,7 +55,7 @@ resource "argocd_application" "this" {
wait = var.app_autosync == { "allow_empty" = tobool(null), "prune" = tobool(null), "self_heal" = tobool(null) } ? false : true

spec {
project = argocd_project.this.metadata.0.name
project = var.argocd_project == null ? argocd_project.this[0].metadata.0.name : var.argocd_project

source {
repo_url = "https://github.com/camptocamp/devops-stack-module-longhorn.git"
Expand All @@ -61,7 +67,7 @@ resource "argocd_application" "this" {
}

destination {
name = "in-cluster"
name = var.destination_cluster
namespace = var.namespace
}

Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ variable "argocd_namespace" {
default = "argocd"
}

variable "argocd_project" {
description = "Name of the Argo CD AppProject where the Application should be created. If not set, the Application will be created in a new AppProject only for this Application."
type = string
default = null
}

variable "argocd_labels" {
description = "Labels to attach to the Argo CD Application resource."
type = map(string)
default = {}
}

variable "destination_cluster" {
description = "Destination cluster where the application should be deployed."
type = string
default = "in-cluster"
}

variable "target_revision" {
description = "Override of target revision of the application chart."
type = string
Expand Down