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

resource/cloudflare_list_item: ensure each entry gets a unique ID #2922

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

jacobbednarz
Copy link
Member

@jacobbednarz jacobbednarz commented Nov 9, 2023

Due to the List service using a polling model and not exposing the resource ID at creation, the provider relied on the assumption that it would be the latest created entry. This however, is incorrect as if you have multiple items added to a single list, they will all share the same ID of the last inserted entry.

To rectify this, we (inefficiently) use a second API call to search for the list item after the polling operation has completed to return the unique ID. This is easiest demonstrated by the IDs outputted by terraform when applying changes.

Without this fix

$ terraform apply

cloudflare_list.example: Creating...
cloudflare_list.example: Creation complete after 0s [id=20443923226b42268668e85b2f968532]
cloudflare_list_item.example_4: Creating...
cloudflare_list_item.example_3: Creating...
cloudflare_list_item.example_1: Creating...
cloudflare_list_item.example_2: Creating...
cloudflare_list_item.example_3: Creation complete after 4s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
cloudflare_list_item.example_1: Creation complete after 5s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
cloudflare_list_item.example_2: Creation complete after 5s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
cloudflare_list_item.example_4: Creation complete after 6s [id=495e8b0f37fd4b9f8ceead7b15e783ad]

And after this fix

$ terraform apply

cloudflare_list.example: Creating...
cloudflare_list.example: Creation complete after 0s [id=a2679b7940624b9aba3ad9987441d281]
cloudflare_list_item.example_4: Creating...
cloudflare_list_item.example_3: Creating...
cloudflare_list_item.example_1: Creating...
cloudflare_list_item.example_2: Creating...
cloudflare_list_item.example_3: Creation complete after 4s [id=bdf686681b654aeab7555fc12be38fb6]
cloudflare_list_item.example_1: Creation complete after 5s [id=68ebd2f8e1c445fd9bcd55a3cb11b692]
cloudflare_list_item.example_2: Creation complete after 5s [id=e8c84aa699dc4f9297b08b0891342e26]
cloudflare_list_item.example_4: Creation complete after 6s [id=a804fba7f3a546198cb58a8f69060964]

Closes #2559
Closes #2848

Due to the List service using a polling model and not exposing the resource ID
at creation, the provider relied on the assumption that it would be the latest
created entry. This however, is incorrect as if you have multiple items added to
a single list, they will all share the same ID of the last inserted entry.

To rectify this, we (inefficiently) use a second API call to search for the list
item after the polling operation has completed to return the unique ID. This is
easiest demonstrated by the IDs outputted by `terraform` when applying changes.

Without this fix

```
$ terraform apply

cloudflare_list.example: Creating...
cloudflare_list.example: Creation complete after 0s [id=20443923226b42268668e85b2f968532]
cloudflare_list_item.example_4: Creating...
cloudflare_list_item.example_3: Creating...
cloudflare_list_item.example_1: Creating...
cloudflare_list_item.example_2: Creating...
cloudflare_list_item.example_3: Creation complete after 4s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
cloudflare_list_item.example_1: Creation complete after 5s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
cloudflare_list_item.example_2: Creation complete after 5s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
cloudflare_list_item.example_4: Creation complete after 6s [id=495e8b0f37fd4b9f8ceead7b15e783ad]
```

And after this fix

```
$ terraform apply

cloudflare_list.example: Creating...
cloudflare_list.example: Creation complete after 0s [id=a2679b7940624b9aba3ad9987441d281]
cloudflare_list_item.example_4: Creating...
cloudflare_list_item.example_3: Creating...
cloudflare_list_item.example_1: Creating...
cloudflare_list_item.example_2: Creating...
cloudflare_list_item.example_3: Creation complete after 4s [id=bdf686681b654aeab7555fc12be38fb6]
cloudflare_list_item.example_1: Creation complete after 5s [id=68ebd2f8e1c445fd9bcd55a3cb11b692]
cloudflare_list_item.example_2: Creation complete after 5s [id=e8c84aa699dc4f9297b08b0891342e26]
cloudflare_list_item.example_4: Creation complete after 6s [id=a804fba7f3a546198cb58a8f69060964]
```
Copy link
Contributor

github-actions bot commented Nov 9, 2023

changelog detected ✅

@jacobbednarz
Copy link
Member Author

acceptance tests all passing

TF_ACC=1 go test ./internal/sdkv2provider -v -run "^TestAccCloudflareListItem_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareListItem_Exists
--- PASS: TestAccCloudflareListItem_Exists (14.67s)
=== RUN   TestAccCloudflareListItem_MultipleItems
--- PASS: TestAccCloudflareListItem_MultipleItems (19.90s)
=== RUN   TestAccCloudflareListItem_Update
--- PASS: TestAccCloudflareListItem_Update (25.07s)
=== RUN   TestAccCloudflareListItem_BadListItemType
--- PASS: TestAccCloudflareListItem_BadListItemType (6.23s)
PASS
ok  	github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider	66.793s

@jacobbednarz jacobbednarz merged commit 837df91 into master Nov 9, 2023
10 checks passed
@jacobbednarz jacobbednarz deleted the ensure-list-items-have-own-ids branch November 9, 2023 03:02
@github-actions github-actions bot added this to the v4.19.0 milestone Nov 9, 2023
github-actions bot pushed a commit that referenced this pull request Nov 9, 2023
@saintsinnerr
Copy link

Hello, when will we be able to use 4.19 version with fix of this bug?

Copy link
Contributor

This functionality has been released in v4.19.0 of the Terraform Cloudflare Provider.

Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants