From 13765f4eee652b20245570c9b34385db06cd6ad5 Mon Sep 17 00:00:00 2001 From: Matt Morrison Date: Thu, 30 Jul 2020 14:22:58 +1200 Subject: [PATCH] Convert colons to underscores --- pkg/tfkschema/name_mapper.go | 6 +++++- pkg/tfkschema/name_mapper_test.go | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/tfkschema/name_mapper.go b/pkg/tfkschema/name_mapper.go index 7f32852..b153086 100644 --- a/pkg/tfkschema/name_mapper.go +++ b/pkg/tfkschema/name_mapper.go @@ -2,11 +2,12 @@ package tfkschema import ( "fmt" - "github.com/sl1pm4t/k2tf/pkg/k8sutils" "os" "reflect" "strings" + "github.com/sl1pm4t/k2tf/pkg/k8sutils" + "github.com/jinzhu/inflection" "k8s.io/apimachinery/pkg/runtime" @@ -96,6 +97,9 @@ func NormalizeTerraformName(s string, toSingular bool, path string) string { } s = strcase.ToSnake(s) + // colons are not allowed by Terraform + s = strings.ReplaceAll(s, ":", "_") + return s } diff --git a/pkg/tfkschema/name_mapper_test.go b/pkg/tfkschema/name_mapper_test.go index 66d8bcd..d5ac273 100644 --- a/pkg/tfkschema/name_mapper_test.go +++ b/pkg/tfkschema/name_mapper_test.go @@ -243,6 +243,15 @@ func Test_NormalizeTerraformName(t *testing.T) { }, "capabilities", }, + { + "metallb-system:speaker", + args{ + "metallb-system:speaker", + true, + "", + }, + "metallb_system_speaker", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {