pulumi / pulumi-converter-terraform

Apache License 2.0
9 stars 3 forks source link

Consider automatically fixing duplicate resource names #146

Open t0yv0 opened 5 months ago

t0yv0 commented 5 months ago

This causes some example fallout. Once we have all data in Metabase we can find out how significant that is. Example:


resource "cloudflare_access_application" "staging_app" {
  zone_id                   = "0da42c8d2132a9ddaf714f9e7c920711"
  name                      = "staging application"
  domain                    = "staging.example.com"
  type                      = "self_hosted"
  session_duration          = "24h"
  auto_redirect_to_identity = false
}

# With CORS configuration
resource "cloudflare_access_application" "staging_app" {
  zone_id          = "0da42c8d2132a9ddaf714f9e7c920711"
  name             = "staging application"
  domain           = "staging.example.com"
  type             = "self_hosted"
  session_duration = "24h"
  cors_headers {
    allowed_methods   = ["GET", "POST", "OPTIONS"]
    allowed_origins   = ["https://example.com"]
    allow_credentials = true
    max_age           = 10
  }
}
t0yv0@Antons-MacBook-Pro> jq '.|select(.ExampleName=="#/resources/cloudflare:index/accessApplication:AccessApplication")' cov/byExample.json                                                                                                                 ~/bugs/ci-mgmt-889/pulumi-cloudflare
{
  "ExampleName": "#/resources/cloudflare:index/accessApplication:AccessApplication",
  "OriginalHCL": "resource \"cloudflare_access_application\" \"staging_app\" {\n  zone_id                   = \"0da42c8d2132a9ddaf714f9e7c920711\"\n  name                      = \"staging application\"\n  domain                    = \"staging.example.com\"\n  type                      = \"self_hosted\"\n  session_duration          = \"24h\"\n  auto_redirect_to_identity = false\n}\n\n# With CORS configuration\nresource \"cloudflare_access_application\" \"staging_app\" {\n  zone_id          = \"0da42c8d2132a9ddaf714f9e7c920711\"\n  name             = \"staging application\"\n  domain           = \"staging.example.com\"\n  type             = \"self_hosted\"\n  session_duration = \"24h\"\n  cors_headers {\n    allowed_methods   = [\"GET\", \"POST\", \"OPTIONS\"]\n    allowed_origins   = [\"https://example.com\"]\n    allow_credentials = true\n    max_age           = 10\n  }\n}\n",
  "ConversionResults": {
    "csharp": {
      "FailureSeverity": 2,
      "FailureInfo": "Duplicate resource \"cloudflare_access_application\" configuration: A cloudflare_access_application resource named \"staging_app\" was already declared at /e135.tf:1,1-55. Resource names must be unique per type in each module.",
      "Program": "",
      "TranslationCount": 1
    },
    "go": {
      "FailureSeverity": 2,
      "FailureInfo": "Duplicate resource \"cloudflare_access_application\" configuration: A cloudflare_access_application resource named \"staging_app\" was already declared at /e135.tf:1,1-55. Resource names must be unique per type in each module.",
      "Program": "",
      "TranslationCount": 1
    },
    "java": {
      "FailureSeverity": 2,
      "FailureInfo": "Duplicate resource \"cloudflare_access_application\" configuration: A cloudflare_access_application resource named \"staging_app\" was already declared at /e135.tf:1,1-55. Resource names must be unique per type in each module.",
      "Program": "",
      "TranslationCount": 1
    },
    "python": {
      "FailureSeverity": 2,
      "FailureInfo": "Duplicate resource \"cloudflare_access_application\" configuration: A cloudflare_access_application resource named \"staging_app\" was already declared at /e135.tf:1,1-55. Resource names must be unique per type in each module.",
      "Program": "",
      "TranslationCount": 1
    },
    "typescript": {
      "FailureSeverity": 2,
      "FailureInfo": "Duplicate resource \"cloudflare_access_application\" configuration: A cloudflare_access_application resource named \"staging_app\" was already declared at /e135.tf:1,1-55. Resource names must be unique per type in each module.",
      "Program": "",
      "TranslationCount": 1
    },
    "yaml": {
      "FailureSeverity": 2,
      "FailureInfo": "Duplicate resource \"cloudflare_access_application\" configuration: A cloudflare_access_application resource named \"staging_app\" was already declared at /e135.tf:1,1-55. Resource names must be unique per type in each module.",
      "Program": "",
      "TranslationCount": 1
    }
  }
}
Frassle commented 5 months ago

Awkward as these are invalid programs but feels reasonable to make the converter good enough to translate them.

t0yv0 commented 5 months ago

Yeah I think I'd wait on this until we have good metabase stats, then we'll see how impactful these things are and can decide the tradeoffs. Just filing everything I find for now.