Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Log warning for assets that did not return a value for ID field#218

Merged
melinath merged 1 commit into
GoogleCloudPlatform:mainfrom
c2thorn:storage-iam-fix
Jul 19, 2021
Merged

Log warning for assets that did not return a value for ID field#218
melinath merged 1 commit into
GoogleCloudPlatform:mainfrom
c2thorn:storage-iam-fix

Conversation

@c2thorn

@c2thorn c2thorn commented May 17, 2021

Copy link
Copy Markdown
Member

Closes #216

Tested with a tfjson plan identical to the one in the issue.

@c2thorn

c2thorn commented Jun 2, 2021

Copy link
Copy Markdown
Member Author

Looks like there's a panic caused by GoogleCloudPlatform/terraform-google-conversion#709

@c2thorn c2thorn marked this pull request as ready for review June 3, 2021 19:17
@c2thorn c2thorn requested a review from melinath June 3, 2021 19:17

@melinath melinath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as an implementation; would it be possible to add an integration test? I assume we would need to avoid using a module, but perhaps we could explicitly set up the underlying relationship that caused the crash?

Adding tests for resources is documented a bit here: https://github.com/GoogleCloudPlatform/terraform-validator/blob/master/docs/add_new_resource.md#2-terraform-validator

I imagine it would be similar to the example_storage_bucket_iam_member tests.

@c2thorn c2thorn force-pushed the storage-iam-fix branch from 822a0bb to 42338fb Compare June 9, 2021 19:26
@melinath

melinath commented Jun 9, 2021

Copy link
Copy Markdown
Member

The tests are passing for both me & @c2thorn locally. This is because the results of convert are not fully deterministic.

We use map[string]Asset to store assets internally; Golang maps are not ordered. So when we pull out the list of assets, we order them by Asset Name - for example, //storage.googleapis.com/placeholder-c2WD8F2q (the last bit is generated by terraform-google-conversion).

In test runs, we then "normalize" assets for comparison, which replaces placeholder-.* with placeholder-foobar so that we can have passing tests even with randomly-generated asset names. This obscures the fact that the assets were first sorted by their random name (which means that the results are not deterministic even though they're sorted by name.)

@melinath

melinath commented Jun 9, 2021

Copy link
Copy Markdown
Member

It's odd that it seems to pass consistently for me locally though... :-/

@melinath

melinath commented Jun 9, 2021

Copy link
Copy Markdown
Member

Okay, so if I am just running the one test, it always gets the same values for the random placeholder strings. This is almost certainly because we use rand.Intn to generate the placeholder values, which relies on Golang's pseudo-random builtins, which always start with the same randomness seed.

So, the full test suite is probably failing because it's preceded by a bunch of randIntn calls, resulting in output that happens to be different than what we get just running that test. We're lucky we caught this now!

On the plus side, this means that if we can find a thread-safe way to reset the seed before each test, we could make all tests deterministic with regard to their generated strings. If that doesn't work we'll have to find some other solution.

@c2thorn

c2thorn commented Jul 19, 2021

Copy link
Copy Markdown
Member Author

@melinath Moved the test failure to its own issue, skipped the test and rebased.

@melinath melinath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@melinath melinath merged commit d6af2f0 into GoogleCloudPlatform:main Jul 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terraform-validator crashes when validating google_storage_bucket with google_storage_bucket_iam_member

2 participants