terraform kubernetes 提供程序的多行字符串注释
Multiline string annotations for terraform kubernetes provider
我想设置 Ambassador as an API Gateway for kubernetes using terraform. There are several ways how to configure Ambassador. The recommended way, according to documentation,是通过为路由和暴露在集群外部的每个服务使用 kubernetes 注释。使用 kubernetes yaml 配置可以轻松完成此操作:
kind: Service
apiVersion: v1
metadata:
name: my-service
annotations:
getambassador.io/config: |
---
apiVersion: ambassador/v0
kind: Mapping
name: my_service_mapping
prefix: /my-service/
service: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
getambassador.io/config
字段的值以 |
开头表明它是一个多行字符串值。如何使用 Terraform HCL 实现相同的目的?
Terraform 文档包含 section 关于使用 <<EOF your multiline string EOF
:
的多行字符串
resource "kubernetes_service" "my-service" {
"metadata" {
name = "my-service"
annotations {
"getambassador.io/config" = <<EOF
apiVersion: ambassador/v0
kind: Mapping
name: my_service_mapping
prefix: /my-service/
service: my-service
EOF
}
}
"spec" {
selector {
app = "MyApp"
}
port {
protocol = "TCP"
port = 80
target_port = "9376"
}
}
}
确保 yaml 配置中没有三重破折号 (---
)。 Terraform 错误地解析了它。
我想设置 Ambassador as an API Gateway for kubernetes using terraform. There are several ways how to configure Ambassador. The recommended way, according to documentation,是通过为路由和暴露在集群外部的每个服务使用 kubernetes 注释。使用 kubernetes yaml 配置可以轻松完成此操作:
kind: Service
apiVersion: v1
metadata:
name: my-service
annotations:
getambassador.io/config: |
---
apiVersion: ambassador/v0
kind: Mapping
name: my_service_mapping
prefix: /my-service/
service: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
getambassador.io/config
字段的值以 |
开头表明它是一个多行字符串值。如何使用 Terraform HCL 实现相同的目的?
Terraform 文档包含 section 关于使用 <<EOF your multiline string EOF
:
resource "kubernetes_service" "my-service" {
"metadata" {
name = "my-service"
annotations {
"getambassador.io/config" = <<EOF
apiVersion: ambassador/v0
kind: Mapping
name: my_service_mapping
prefix: /my-service/
service: my-service
EOF
}
}
"spec" {
selector {
app = "MyApp"
}
port {
protocol = "TCP"
port = 80
target_port = "9376"
}
}
}
确保 yaml 配置中没有三重破折号 (---
)。 Terraform 错误地解析了它。