From 0af6f21cc75c99753456c0d24ab7928a92b11c02 Mon Sep 17 00:00:00 2001 From: delvh Date: Wed, 28 Feb 2024 22:45:37 +0100 Subject: [PATCH] Fix weird Terraform bugs with Dapr config files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous resource type had weird bugs and is no longer maintained, so switch to direct YAML manifests. Note: I have been unable to test if the change works as intended as my test cluster already has Dapr installed in a different namespace > │ Error: Unable to continue with install: ClusterRole "dapr-injector" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-namespace" must equal "gits": current value is "misarch" However, I'm 95% sure it works regardless. --- dapr.tf | 83 +++++++++++++++++++++++---------------------------------- main.tf | 9 +++++++ 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/dapr.tf b/dapr.tf index 089abe9..9e22839 100644 --- a/dapr.tf +++ b/dapr.tf @@ -23,61 +23,44 @@ resource "helm_release" "redis" { } } -# -- comment out the two resources below when initially creating the cluster, somehow this fails to plan on the first run - -resource "kubernetes_manifest" "dapr_state_config" { +resource "kubectl_manifest" "dapr_state_config" { depends_on = [kubernetes_namespace.gits] - manifest = { - "apiVersion" = "dapr.io/v1alpha1" - "kind" = "Component" - "metadata" = { - "name" = "statestore" - namespace = kubernetes_namespace.gits.metadata[0].name - } - "spec" = { - "type" = "state.redis" - "version" = "v1" - - "metadata" = [ - { - "name" = "redisHost" - "value" = "redis-master:6379" - }, - { - "name" = "redisPassword" - "value" = random_password.redis.result - } - ] - } - } -} + yaml_body = <<-EOF + apiVersion: "dapr.io/v1alpha1" + kind: "Component" + metadata: + name: "statestore" + namespace: ${kubernetes_namespace.gits.metadata[0].name} + spec: + type: "state.redis" + version: "v1" + metadata: + - name: "redisHost" + value: "redis-master:6379" + - name: "redisPassword" + value: ${random_password.redis.result} + EOF +} -resource "kubernetes_manifest" "dapr_pubsub_config" { +resource "kubectl_manifest" "dapr_pubsub_config" { depends_on = [kubernetes_namespace.gits] - manifest = { - "apiVersion" = "dapr.io/v1alpha1" - "kind" = "Component" - "metadata" = { - "name" = "gits" - namespace = kubernetes_namespace.gits.metadata[0].name - } + yaml_body = <<-EOF + apiVersion: "dapr.io/v1alpha1" + kind: "Component" + metadata: + name: "gits" + namespace: ${kubernetes_namespace.gits.metadata[0].name} - "spec" = { - "type" = "pubsub.redis" - "version" = "v1" + spec: + type: "pubsub.redis" + version: "v1" - "metadata" = [ - { - "name" = "redisHost" - "value" = "redis-master:6379" - }, - { - "name" = "redisPassword" - "value" = random_password.redis.result - } - ] - } - } + metadata: + - name: "redisHost" + value: "redis-master:6379" + - name: "redisPassword" + value: ${random_password.redis.result} + EOF } diff --git a/main.tf b/main.tf index da48677..c17d3e3 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + kubectl = { + source = "gavinbunney/kubectl" + version = "~> 1.14.0" + } + } +} + provider "kubernetes" { config_path = "./kubeconfig.yaml" }