这是我的结构:
.
├── development
│ ├── inputs.tf
│ ├── main.tf
│ └── provider.tf
└── modules
├── kafka
│ ├── inputs.tf
│ └── main.tf
└── zookeeper
├── inputs.tf
├── main.tf
└── outputs.tf
每个kafka
和zookeeper
模块是:
_/modules/kafka/main.tf
中的Kafka模块:
resource "helm_release" "kafka" {
name = "kafka"
repository = "https://charts.bitnami.com/bitnami"
chart = "kafka"
version = "10.3.3"
namespace = var.namespace
set {
name = "zookeeper.enabled"
value = false
}
set {
name = "externalZookeeper.servers"
value = var.zookeeper_service
}
set {
name = "replicaCount"
value = var.nodes
}
}
_/modules/zookeeper/main.tf
中的Zookeeper模块:
resource "helm_release" "zookeeper" {
name = "zookeeper"
repository = "https://charts.bitnami.com/bitnami"
chart = "zookeeper"
version = "5.14.3"
namespace = var.namespace
}
如您所见,kafka模块需要知道哪个是在zookeepper
前面创建的服务。
我想在zookeeper
模块上生成输出,以获取创建的服务,并同时在kafka和zookeeper之间创建模块依赖关系。我的意思是,kafka
模块需要zookeeper
。
我创建了一个_/modules/zookeeper/output.tf
:
output "service_name" {
description = "The name of the created zookeeper service."
value = "zookeeper"
}
我想用从"zookeeper"
获得的任何值替换helm_release
字符串文字。
这里的问题是zookeeper
舵图正在创建此服务:
apiVersion: v1
kind: Service
metadata:
name: {{ template "zookeeper.fullname" . }}
...
您可以找到头盔图表代码here。
一旦正确部署头盔,如何获得该值并将其作为zookeeper
模块输出传递?