英文:
How to create CDKTF script in golang for creating Kubernetes Namespaces
问题
我有一个用于创建Kubernetes命名空间的Terraform脚本,但是在CKDTF中找不到用于在Go语言中执行相同任务的包的导入语句。
resource "kubernetes_namespace" "stage-namespace-1" {
depends_on = [google_container_cluster.primary]
metadata {
annotations = {
name = "example-annotation"
}
labels = {
mylabel = "label-value"
}
name = "stage-namespace-1"
}
}
我正在使用这个包来创建其他资源。
// main.go
package main
import (
...
"github.com/cdktf/cdktf-provider-google-go/google/v5/computeinstance"
"github.com/cdktf/cdktf-provider-google-go/google/v5/computenetwork"
"github.com/cdktf/cdktf-provider-google-go/google/v5/computesubnetwork"
"github.com/cdktf/cdktf-provider-google-go/google/v5/containercluster"
"github.com/cdktf/cdktf-provider-google-go/google/v5/provider"
...
)
英文:
I have Terraform script for creating Kubernetes namespaces, but can not find the import statement for package in golang which would do the same job in CKDTF for go lang.
resource "kubernetes_namespace" "stage-namespace-1" {
depends_on = [google_container_cluster.primary]
metadata {
annotations = {
name = "example-annotation"
}
labels = {
mylabel = "label-value"
}
name = "stage-namespace-1"
}
}
I am using this package for creating other resources
// main.go
package main
import (
...
"github.com/cdktf/cdktf-provider-google-go/google/v5/computeinstance"
"github.com/cdktf/cdktf-provider-google-go/google/v5/computenetwork"
"github.com/cdktf/cdktf-provider-google-go/google/v5/computesubnetwork"
"github.com/cdktf/cdktf-provider-google-go/google/v5/containercluster"
"github.com/cdktf/cdktf-provider-google-go/google/v5/provider"
...
)
答案1
得分: 1
你需要安装预构建的 Kubernetes 提供程序:https://github.com/cdktf/cdktf-provider-kubernetes-go。你可以通过运行 cdktf provider add kubernetes
来完成安装。
在导入语句中,可以这样使用:
import (
...
kubernetesprovider "github.com/cdktf/cdktf-provider-kubernetes-go/kubernetes/v5/provider"
....
)
kubernetesprovider
用作别名,以避免与 Google 或 AWS 提供程序发生冲突。
英文:
You need to install the pre-built kubernetes provider: https://github.com/cdktf/cdktf-provider-kubernetes-go. You can do this by running cdktf provider add kubernetes
.
In import statement it can be used on this way
import (
...
kubernetesprovider "github.com/cdktf/cdktf-provider-kubernetes-go/kubernetes/v5/provider"
....
)
kubernetesprovider
is used as alias to avoid conflicts with google or aws provider
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论