sl1pm4t / k2tf

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

fix: dots are not allowed in Terraform names #101

Closed sbellone closed 2 years ago

sbellone commented 2 years ago

Hi, thanks for this very useful tool! Today I've tried to convert Google's Custom Metrics Adapter and I got invalid names in the final result. Indeed, dots are not valid in resource names and their yaml file contains metadata names such as v1beta1.custom.metrics.k8s.io.

Before:

resource "kubernetes_api_service" "v_1_beta_1_.custom.metrics.k_8_s.io" {
  metadata {
    name = "v1beta1.custom.metrics.k8s.io"
  }

After:

resource "kubernetes_api_service" "v_1_beta_1__custom_metrics_k_8_s_io" {
  metadata {
    name = "v1beta1.custom.metrics.k8s.io"
  }
sbellone commented 2 years ago

Unrelated but I'm using the occasion to ask: When looking at the tests, it seems that the toSingular parameter doesn't seem to work:

{
    "labels",
    args{
        "labels",
        true,
        "",
    },
    "labels",
},

Did I miss something?

sl1pm4t commented 2 years ago

Thanks @sbellone. As for toSingular - there are a few exceptions setup to prevent it from singularizing certain words to match the TF Kubernetes provider schema. See - https://github.com/sl1pm4t/k2tf/blob/master/pkg/tfkschema/name_mapper.go#L20

sbellone commented 2 years ago

Oh I see, I had missed that, thanks :+1: