Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudflare_logpush_job import not working/ generate works fine #381

Open
2 tasks done
abhiramani-iptiq opened this issue Mar 31, 2022 · 3 comments
Open
2 tasks done

Comments

@abhiramani-iptiq
Copy link

Confirmation

  • My issue isn't already found on the issue tracker.
  • 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/cobra@v1.3.0/command.go:860 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0x16879a0)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/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

@abhiramani-iptiq
Copy link
Author

this autogenerated name when it was created is causing some issues

resource "cloudflare_logpush_job" "terraform_managed_resource_20064.000000" {

}

@Arnall
Copy link

Arnall commented Aug 23, 2022

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:

fmt.Fprint(cmd.OutOrStdout(), buildCompositeID(resourceType, data.(map[string]interface{})["id"].(string)))

Generate has been "badly fixed" : #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.

@Arnall
Copy link

Arnall commented Aug 24, 2022

BTW according to the documentation import of logpush_jobs is not supported (as the time of v0.8.2):

| [cloudflare_logpush_job](https://www.terraform.io/docs/providers/cloudflare/r/logpush_job) | Zone |||

var resourceImportStringFormats = map[string]string{
"cloudflare_access_rule": ":identifer_type/:identifer_value/:id",
"cloudflare_account_member": ":account_id/:id",
"cloudflare_argo": ":zone_id/argo",
"cloudflare_argo_tunnel": ":account_id/:id",
"cloudflare_byo_ip_prefix": ":id",
"cloudflare_certificate_pack": ":zone_id/:id",
"cloudflare_custom_pages": ":identifer_type/:identifer_value/:id",
"cloudflare_filter": ":zone_id/:id",
"cloudflare_firewall_rule": ":zone_id/:id",
"cloudflare_healthcheck": ":zone_id/:id",
"cloudflare_custom_hostname": ":zone_id/:id",
"cloudflare_custom_ssl": ":zone_id/:id",
"cloudflare_ip_list": ":account_id/:id",
"cloudflare_origin_ca_certificate": ":id",
"cloudflare_page_rule": ":zone_id/:id",
"cloudflare_rate_limit": ":zone_id/:id",
"cloudflare_record": ":zone_id/:id",
"cloudflare_spectrum_application": ":zone_id/:id",
"cloudflare_waf_override": ":zone_id/:id",
"cloudflare_waiting_room": ":zone_id/:id",
"cloudflare_worker_route": ":zone_id/:id",
"cloudflare_workers_kv_namespace": ":id",
"cloudflare_zone": ":id",
"cloudflare_zone_lockdown": ":zone_id/:id",
}

There is no mapping for logpush_jobs and:

func buildCompositeID(resourceType, resourceID string) string {
if _, ok := resourceImportStringFormats[resourceType]; !ok {
log.Fatalf("%s does not have an import format defined", resourceType)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants