sl1pm4t / k2tf

Kubernetes YAML to Terraform HCL converter
Mozilla Public License 2.0
1.17k stars 108 forks source link

Invalid resource names #50

Closed ajchiarello closed 4 years ago

ajchiarello commented 4 years ago

When converting a yaml where the name field contains a colon, this is replicated to the resource name, which results in an invalid name for a terraform resource and fails terraform validation.

For example:

apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: app: metallb name: metallb-system:speaker roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: metallb-system:speaker subjects: - kind: ServiceAccount name: speaker namespace: metallb-system

becomes

resource "kubernetes_cluster_role_binding" "metallb_system:speaker" { metadata { name = "metallb-system:speaker" labels = { app = "metallb" } } subject { kind = "ServiceAccount" name = "speaker" namespace = "metallb-system" } role_ref { api_group = "rbac.authorization.k8s.io" kind = "ClusterRole" name = "metallb-system:speaker" } }

tynril commented 4 years ago

I have encountered this issue when converting the Metrics Server files, located there: https://github.com/kubernetes-sigs/metrics-server/tree/v0.3.6/deploy/1.8+

stntmaniiac commented 4 years ago

This is the intentional restriction on terraform v0.12 https://github.com/hashicorp/terraform/issues/19919