Skip to content

Commit

Permalink
Merge pull request #119 from sl1pm4t/hcl/v2
Browse files Browse the repository at this point in the history
Replace hcl2 with hcl/v2
  • Loading branch information
sl1pm4t authored May 18, 2024
2 parents 2a1c89f + 4d4ba1a commit 998e237
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 89 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80
github.com/hashicorp/hcl/v2 v2.17.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/hashicorp/terraform-provider-kubernetes v1.13.4-0.20230417041302-5de2ce8af29e
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
Expand Down Expand Up @@ -34,7 +34,6 @@ require (
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg v1.0.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -67,7 +66,6 @@ require (
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.5.0 // indirect
github.com/hashicorp/hcl/v2 v2.15.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.18.1 // indirect
github.com/hashicorp/terraform-json v0.15.0 // indirect
Expand Down
32 changes: 2 additions & 30 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hcl_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/sl1pm4t/k2tf/pkg/tfkschema"
"strings"

"github.com/hashicorp/hcl2/hclwrite"
"github.com/hashicorp/hcl/v2/hclwrite"
log "github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
)
Expand Down
2 changes: 1 addition & 1 deletion hcl_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/rs/zerolog"

"github.com/hashicorp/hcl2/hclwrite"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/mitchellh/reflectwalk"
"github.com/rs/zerolog/log"
"github.com/zclconf/go-cty/cty"
Expand Down
2 changes: 1 addition & 1 deletion hcl_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/sl1pm4t/k2tf/pkg/testutils"

"github.com/hashicorp/hcl2/hclwrite"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/hashicorp/hcl/hcl/printer"
"github.com/hashicorp/hcl2/hclwrite"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/sl1pm4t/k2tf/pkg/file_io"
"github.com/sl1pm4t/k2tf/pkg/tfkschema"
flag "github.com/spf13/pflag"
Expand Down
28 changes: 20 additions & 8 deletions test-fixtures/basicDeployment.tf.golden
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
resource "kubernetes_deployment" "baz_app" {
metadata {
name = "baz-app"
namespace = "bat"
annotations = { foo = "fam" }
name = "baz-app"
namespace = "bat"
annotations = {
foo = "fam"
}
}
spec {
replicas = 2
selector {
match_labels = { app = "nginx" }
match_labels = {
app = "nginx"
}
}
template {
metadata {
labels = { app = "nginx" }
annotations = { foo = "fam" }
labels = {
app = "nginx"
}
annotations = {
foo = "fam"
}
}
spec {
container {
Expand All @@ -23,8 +31,12 @@ resource "kubernetes_deployment" "baz_app" {
container_port = 80
}
resources {
limits = { memory = "1Gi" }
requests = { cpu = "1" }
limits = {
memory = "1Gi"
}
requests = {
cpu = "1"
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion test-fixtures/clusterRole.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ resource "kubernetes_cluster_role" "monitoring" {
}
aggregation_rule {
cluster_role_selectors {
match_labels = { "rbac.example.com/aggregate-to-monitoring" = "true" }
match_labels = {
"rbac.example.com/aggregate-to-monitoring" = "true"
}
}
}
}
10 changes: 8 additions & 2 deletions test-fixtures/configMap.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ resource "kubernetes_config_map" "foo_config_map" {
metadata {
name = "foo-config-map"
namespace = "bar"
labels = { lbl1 = "somevalue", lbl2 = "another" }
labels = {
lbl1 = "somevalue"
lbl2 = "another"
}
}
data = {
item1 = "wow"
item2 = "wee"
}
data = { item1 = "wow", item2 = "wee" }
}
20 changes: 15 additions & 5 deletions test-fixtures/daemonset.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@ resource "kubernetes_daemonset" "terraform_example" {
metadata {
name = "terraform-example"
namespace = "something"
labels = { test = "MyExampleApp" }
labels = {
test = "MyExampleApp"
}
}
spec {
selector {
match_labels = { test = "MyExampleApp" }
match_labels = {
test = "MyExampleApp"
}
}
template {
metadata {
labels = { test = "MyExampleApp" }
labels = {
test = "MyExampleApp"
}
}
spec {
container {
name = "example"
image = "nginx:1.7.8"
resources {
limits = { memory = "512Mi" }
requests = { cpu = "250m" }
limits = {
memory = "512Mi"
}
requests = {
cpu = "250m"
}
}
}
}
Expand Down
26 changes: 20 additions & 6 deletions test-fixtures/deployment.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ resource "kubernetes_deployment" "backend_api" {
metadata {
name = "backend-api"
namespace = "default"
labels = { app = "backend-api" }
labels = {
app = "backend-api"
}
}
spec {
replicas = 4
selector {
match_labels = { app = "backend-api" }
match_labels = {
app = "backend-api"
}
}
template {
metadata {
labels = { app = "backend-api" }
annotations = { "prometheus.io/port" = "8080", "prometheus.io/scheme" = "http", "prometheus.io/scrape" = "true" }
labels = {
app = "backend-api"
}
annotations = {
"prometheus.io/port" = "8080"
"prometheus.io/scheme" = "http"
"prometheus.io/scrape" = "true"
}
}
spec {
volume {
Expand Down Expand Up @@ -90,8 +100,12 @@ resource "kubernetes_deployment" "backend_api" {
value = "bedba4b80a982b3116dfd56366de3c2d"
}
resources {
limits = { memory = "8Gi" }
requests = { cpu = "300m" }
limits = {
memory = "8Gi"
}
requests = {
cpu = "300m"
}
}
volume_mount {
name = "backend-api-config"
Expand Down
8 changes: 6 additions & 2 deletions test-fixtures/deployment2Containers.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ resource "kubernetes_deployment" "backend_api" {
}
spec {
selector {
match_labels = { app = "backend-api" }
match_labels = {
app = "backend-api"
}
}
template {
metadata {
labels = { app = "backend-api" }
labels = {
app = "backend-api"
}
}
spec {
container {
Expand Down
8 changes: 5 additions & 3 deletions test-fixtures/endpoints.tf.golden
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
resource "kubernetes_endpoints" "backend" {
metadata {
name = "backend"
namespace = "default"
annotations = { "alpha.istio.io/kubernetes-serviceaccounts" = "default" }
name = "backend"
namespace = "default"
annotations = {
"alpha.istio.io/kubernetes-serviceaccounts" = "default"
}
}
subset {
address {
Expand Down
17 changes: 13 additions & 4 deletions test-fixtures/issue-28.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ resource "kubernetes_daemonset" "nvidia_driver_installer" {
metadata {
name = "nvidia-driver-installer"
namespace = "kube-system"
labels = { k8s-app = "nvidia-driver-installer" }
labels = {
k8s-app = "nvidia-driver-installer"
}
}
spec {
selector {
match_labels = { k8s-app = "nvidia-driver-installer" }
match_labels = {
k8s-app = "nvidia-driver-installer"
}
}
template {
metadata {
labels = { k8s-app = "nvidia-driver-installer", name = "nvidia-driver-installer" }
labels = {
k8s-app = "nvidia-driver-installer"
name = "nvidia-driver-installer"
}
}
spec {
volume {
Expand Down Expand Up @@ -75,7 +82,9 @@ resource "kubernetes_daemonset" "nvidia_driver_installer" {
value = "/build/cos-tools"
}
resources {
requests = { cpu = "150m" }
requests = {
cpu = "150m"
}
}
volume_mount {
name = "nvidia-install-dir-host"
Expand Down
4 changes: 3 additions & 1 deletion test-fixtures/issue-48.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ resource "kubernetes_replication_controller" "echoheaders" {
replicas = 1
template {
metadata {
labels = { app = "echoheaders" }
labels = {
app = "echoheaders"
}
}
spec {
container {
Expand Down
6 changes: 4 additions & 2 deletions test-fixtures/namespace.tf.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
resource "kubernetes_namespace" "cert_manager" {
metadata {
name = "cert-manager"
labels = { "certmanager.k8s.io/disable-validation" = "true" }
name = "cert-manager"
labels = {
"certmanager.k8s.io/disable-validation" = "true"
}
}
}
6 changes: 4 additions & 2 deletions test-fixtures/namespace_w_spec.tf.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
resource "kubernetes_namespace" "cert_manager" {
metadata {
name = "cert-manager"
labels = { "certmanager.k8s.io/disable-validation" = "true" }
name = "cert-manager"
labels = {
"certmanager.k8s.io/disable-validation" = "true"
}
}
}
4 changes: 3 additions & 1 deletion test-fixtures/networkPolicy.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ resource "kubernetes_network_policy" "default_deny" {
}
spec {
pod_selector {
match_labels = { IngressInternal = "active" }
match_labels = {
IngressInternal = "active"
}
}
ingress {
ports {
Expand Down
4 changes: 3 additions & 1 deletion test-fixtures/podDisruptionBudget.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ resource "kubernetes_pod_disruption_budget" "test" {
spec {
min_available = "75%"
selector {
match_labels = { app = "zookeeper" }
match_labels = {
app = "zookeeper"
}
}
}
}
12 changes: 10 additions & 2 deletions test-fixtures/podNodeExporter.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ resource "kubernetes_pod" "node_exporter_7fth_7" {
name = "node-exporter-7fth7"
generate_name = "node-exporter-"
namespace = "prometheus"
labels = { controller-revision-hash = "2418008739", name = "node-exporter", pod-template-generation = "1" }
annotations = { "prometheus.io/port" = "9100", "prometheus.io/scheme" = "http", "prometheus.io/scrape" = "true" }
labels = {
controller-revision-hash = "2418008739"
name = "node-exporter"
pod-template-generation = "1"
}
annotations = {
"prometheus.io/port" = "9100"
"prometheus.io/scheme" = "http"
"prometheus.io/scrape" = "true"
}
}
spec {
volume {
Expand Down
10 changes: 7 additions & 3 deletions test-fixtures/replicationController.tf.golden
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
resource "kubernetes_replication_controller" "es" {
metadata {
name = "es"
labels = { component = "elasticsearch" }
name = "es"
labels = {
component = "elasticsearch"
}
}
spec {
replicas = 1
template {
metadata {
labels = { component = "elasticsearch" }
labels = {
component = "elasticsearch"
}
}
spec {
volume {
Expand Down
Loading

0 comments on commit 998e237

Please sign in to comment.