cloudflare / cf-terraforming

A command line utility to facilitate terraforming your existing Cloudflare resources.
Mozilla Public License 2.0
960 stars 136 forks source link

bug on resource cloudflare_access_group generate code #339

Open antigenius0910 opened 2 years ago

antigenius0910 commented 2 years ago

Confirmation

cf-terraforming version

cf-terraforming v0.5.0

Expected outcome

generated code should be able to use to create Cloudflare infra directly

ᐅ terraform plan
cloudflare_access_application.terraform_managed_resource_31e179a3-56cd-416d-999c-dfc4dd6683b9: Refreshing state... [id=31e179a3-56cd-416d-999c-dfc4dd6683b9]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # cloudflare_access_group.terraform_managed_resource_ae87f986-f801-4806-83cd-9dea7eb85f25 will be created
  + resource "cloudflare_access_group" "terraform_managed_resource_ae87f986-f801-4806-83cd-9dea7eb85f25" {
      + account_id = "56ab6491573957a8cf0731c17c0axxxx"
      + id         = (known after apply)
      + name       = "Internal .xxx apps"
      + zone_id    = (known after apply)

      + include {
          + common_name = "*.xxx.xxx"
        }
    }

  # cloudflare_access_group.terraform_managed_resource_daa77262-7da5-40a6-a1dc-b77c58824b6b will be created
  + resource "cloudflare_access_group" "terraform_managed_resource_daa77262-7da5-40a6-a1dc-b77c58824b6b" {
      + account_id = "56ab6491573957a8cf0731c17c0xxxx"
      + id         = (known after apply)
      + name       = "CircleCI"
      + zone_id    = (known after apply)

      + include {
          + common_name = "circleci.com"
        }
      + include {
          + common_name = "*.circleci.com"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Actual outcome

name under include were generate as a string instead of a list. common_name nested itself 2 times

ᐅ terraform plan
╷
│ Error: Incorrect attribute value type
│ 
│   on cloudflare_access_group.tf line 7, in resource "cloudflare_access_group" "terraform_managed_resource_f5b2072c-d49f-4ca9-9764-6ec03cebfde2":
│    7:       name                 = "Everyone"
│ 
│ Inappropriate value for attribute "name": list of string required.
╵
╷
│ Error: Incorrect attribute value type
│ 
│   on cloudflare_access_group.tf line 16, in resource "cloudflare_access_group" "terraform_managed_resource_daa77262-7da5-40a6-a1dc-b77c58824b6b":
│   16:     common_name = {
│   17:       common_name = "circleci.com"
│   18:     }
│ 
│ Inappropriate value for attribute "common_name": string required.
╵
╷
│ Error: Incorrect attribute value type
│ 
│   on cloudflare_access_group.tf line 21, in resource "cloudflare_access_group" "terraform_managed_resource_daa77262-7da5-40a6-a1dc-b77c58824b6b":
│   21:     common_name = {
│   22:       common_name = "*.circleci.com"
│   23:     }
│ 
│ Inappropriate value for attribute "common_name": string required.

Steps to reproduce

cf-terraforming generate \  
--zone $CLOUDFLARE_ZONE_ID --resource-type $RESOURCE >> $RESOURCE.tf

References

https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/access_group#common_name

danielmotaleite commented 8 months ago

confirmed, still happen quick fix for anyone arriving here: replace name = "Everyone" with name = ["Everyone"]

and

common_name = {
      common_name = "*.circleci.com"
}

with common_name = ["*.circleci.com"]