如何使用Golang创建CDKTF脚本以创建Kubernetes命名空间

huangapple go评论86阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年3月29日 15:48:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75874497.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定