Skip to content

Commit

Permalink
generate: handle non-string values for IDs
Browse files Browse the repository at this point in the history
Updates the name generation to handle scenarios where the ID is not a
string value. This is incredibly uncommon (logpush is the only service
exposing a non-string hash value) however this will fix the crash while
I chase up the internal team whether this is intentionally different.

Fixes #248
  • Loading branch information
jacobbednarz committed Apr 22, 2021
1 parent 54db599 commit 536321b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,15 @@ func generateResources() func(cmd *cobra.Command, args []string) {
if os.Getenv("USE_STATIC_RESOURCE_IDS") == "true" {
resourceID = "terraform_managed_resource"
} else {
resourceID = fmt.Sprintf("terraform_managed_resource_%s", structData["id"].(string))
id := ""
switch structData["id"].(type) {
case float64:
id = fmt.Sprintf("%f", structData["id"].(float64))
default:
id = structData["id"].(string)
}

resourceID = fmt.Sprintf("terraform_managed_resource_%s", id)
}

output += fmt.Sprintf(`resource "%s" "%s" {`+"\n", resourceType, resourceID)
Expand Down

0 comments on commit 536321b

Please sign in to comment.