Skip to content

Commit

Permalink
Merge pull request #71 from sl1pm4t/issue-48
Browse files Browse the repository at this point in the history
Fix panic processing Replication Controller
  • Loading branch information
sl1pm4t authored Jul 30, 2020
2 parents ed44b03 + 10a5557 commit 94dacf8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
9 changes: 6 additions & 3 deletions hcl_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"reflect"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/sl1pm4t/k2tf/pkg/k8sutils"
"github.com/sl1pm4t/k2tf/pkg/tfkschema"
"reflect"
"strconv"

"k8s.io/apimachinery/pkg/util/intstr"

Expand Down Expand Up @@ -216,7 +217,9 @@ func (w *ObjectWalker) closeBlock() *hclBlock {
parent.hasValue = true

if current.isMap {
parent.SetAttributeValue(current.name, cty.MapVal(current.hclMap))
if len(current.hclMap) > 0 {
parent.SetAttributeValue(current.name, cty.MapVal(current.hclMap))
}

} else if !current.inlined {
parent.AppendBlock(current.hcl)
Expand Down
5 changes: 5 additions & 0 deletions hcl_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func TestWriteObject(t *testing.T) {
"kubernetes_stateful_set",
0,
},
{
"issue-48",
"kubernetes_replication_controller",
0,
},
}

for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func Test_readFilesInput(t *testing.T) {
{
"test-fixtures",
"test-fixtures",
19,
20,
},
{
"test-fixtures/",
"test-fixtures/",
19,
20,
},
{
"test-fixtures/nested/server-clusterrole.yaml",
Expand Down
23 changes: 23 additions & 0 deletions test-fixtures/issue-48.tf.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "kubernetes_replication_controller" "echoheaders" {
metadata {
name = "echoheaders"
namespace = "platform"
}
spec {
replicas = 1
template {
metadata {
labels = { app = "echoheaders" }
}
spec {
container {
name = "echoheaders"
image = "k8s.gcr.io/echoserver:1.10"
port {
container_port = 8080
}
}
}
}
}
}
19 changes: 19 additions & 0 deletions test-fixtures/issue-48.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: ReplicationController
metadata:
name: echoheaders
namespace: platform
spec:
replicas: 1
template:
metadata:
labels:
app: echoheaders
spec:
selector:
app: echoheaders
containers:
- name: echoheaders
image: k8s.gcr.io/echoserver:1.10
ports:
- containerPort: 8080

0 comments on commit 94dacf8

Please sign in to comment.