sl1pm4t / k2tf

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

convert requests in resources need to be corrected #76

Closed prakash-26790 closed 2 years ago

prakash-26790 commented 3 years ago

Thanks for k2tf. Saved lots of time.

Issue Noticed: I have k8s deployment file which contains resources block with requests block. converted using k2tf Once i converted I was getting issue

Error: Blocks of type "requests" are not expected here. Did you mean to define argument "requests"? If so, use the equals sign to assign it a value.

Need fix: k2tf converts resources blocks like below:

          resources {
            requests {
              cpu    = "250m"
              memory = "128Mi"
            }
          }

But terraform expects like

          resources {
            requests = {
              cpu    = "250m"
              memory = "128Mi"
            }
          }

Need to assign = to assign values to requests.

Example in Terraform Document

Thanks, Prakash

derjust commented 3 years ago

To be precise that is a change in the Kubernetes-Provider that was introduced with v2.0.

Not sure which version of the provider k2tf is targeting - just saying

sl1pm4t commented 2 years ago

k2tf has been updated to use the terraform-kubernetes-provider v2.5.0, so this should be resolved now.

As a test I rendered the test-fixtures/deployment.yaml file in this repo to deployment.tf then ran terraform against it:

 ❯ tf validate 
Success! The configuration is valid.

 ❯ tf plan | grep -A 8 resources 
                      + resources {
                          + limits   = (known after apply)
                          + requests = (known after apply)
                        }

                      + security_context {
                          + allow_privilege_escalation = true
                          + privileged                 = false
                          + read_only_root_filesystem  = false
--
                      + resources {
                          + limits   = {
                              + "memory" = "8Gi"
                            }
                          + requests = {
                              + "cpu" = "300m"
                            }
                        }

 ❯ tf version 
Terraform v1.0.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/kubernetes v2.5.0

Your version of Terraform is out of date! The latest version
is 1.0.8. You can update by downloading from https://www.terraform.io/downloads.html