cf-terraforming
cf-terraforming copied to clipboard
cloudflare_logpush_job import not working/ generate works fine
Confirmation
- [X] My issue isn't already found on the issue tracker.
- [X] I have replicated my issue using the latest version of the library and it is still present.
cf-terraforming version
0.6.3
Expected outcome
should import my state
Actual outcome
panic: interface conversion: interface {} is float64, not string
goroutine 1 [running]: github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.runImport.func1(0x1687720, {0xdf4078, 0x6, 0x6}) /home/runner/work/cf-terraforming/cf-terraforming/internal/app/cf-terraforming/cmd/import.go:264 +0x1c7f github.com/spf13/cobra.(*Command).execute(0x1687720, {0xc000306a80, 0x6, 0x6}) /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x5f8 github.com/spf13/cobra.(*Command).ExecuteC(0x16879a0) /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3bc github.com/spf13/cobra.(*Command).Execute(...) /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:902 github.com/cloudflare/cf-terraforming/internal/app/cf-terraforming/cmd.Execute() /home/runner/work/cf-terraforming/cf-terraforming/internal/app/cf-terraforming/cmd/root.go:30 +0x25 main.main() /home/runner/work/cf-terraforming/cf-terraforming/cmd/cf-terraforming/main.go:8 +0x17
Steps to reproduce
cf-terraforming import -z $zoneid -t $token --resource-type "cloudflare_logpush_job"
References
no
this autogenerated name when it was created is causing some issues
resource "cloudflare_logpush_job" "terraform_managed_resource_20064.000000" {
}
Hello,
The import fails because the ID of LogpushJob is not a string (cf-terraformin uses cloudflare-go):
https://github.com/cloudflare/cloudflare-go/blob/bc05dd24391dc9d2ff71119de1bf66462e863a6f/logpush.go#L14
type LogpushJob struct {
ID int `json:"id,omitempty"`
.../...
}
With cf-terraforming the id is seen as a float64, adding .000000 to the original id.
Import is expecting a string so this line fails: https://github.com/cloudflare/cf-terraforming/blob/347678a9f0d9f03561e5e15b2ceffdbc378e3c75/internal/app/cf-terraforming/cmd/import.go#L264
Generate has been "badly fixed" : https://github.com/cloudflare/cf-terraforming/issues/248
"Badly" because generate should not use a float64 type for the name of the resource. float64 type put a dot in the resource name (12345 => 12345.000000), and as stated in the Terraform doc :
Note: Resource names must start with a letter or underscore, and may contain only letters, digits, underscores, and dashes.
If you try (as indicated here : ) :
terraform import cloudflare_logpush_job.terraform_managed_resource_84727.000000 zone/<zone_id>/84727.000000
it fails with
│ Error: Attribute name required
│
│ on <import-address> line 1:
│ 1: cloudflare_logpush_job.terraform_managed_resource_84727.000000
│
│ Dot must be followed by attribute name.
If you remove the .000000 from the command line:
terraform import cloudflare_logpush_job.terraform_managed_resource_84727 zone/<zone_id>/84727.000000
it also fails
╷
│ Error: Invalid resource name
│
│ on test_logpush.tf line 1, in resource "cloudflare_logpush_job" "terraform_managed_resource_84727.000000":
│ 1: resource "cloudflare_logpush_job" "terraform_managed_resource_84727.000000" {
│
│ A name must start with a letter or underscore and may contain only letters, digits, underscores, and dashes.
So the ID should be converted as a string, the resource name should be terraform_managed_resource_84727, and then the import would work i think.
BTW according to the documentation import of logpush_jobs is not supported (as the time of v0.8.2):
https://github.com/cloudflare/cf-terraforming/blob/edb8506b898cb1037a57239e81f824f18d274e26/README.md?plain=1#L184
https://github.com/cloudflare/cf-terraforming/blob/8e21feeacff40c2b4f217aee4085bba9cb682070/internal/app/cf-terraforming/cmd/import.go#L18-L43
There is no mapping for logpush_jobs and:
https://github.com/cloudflare/cf-terraforming/blob/8e21feeacff40c2b4f217aee4085bba9cb682070/internal/app/cf-terraforming/cmd/import.go#L297-L300