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/github_repository_webhook: Avoid spurious diff #133

Merged
merged 1 commit into from
Aug 14, 2018

Conversation

radeksimko
Copy link
Contributor

Fixes #81

TF_ACC=1 go test ./github -v -run=TestAccGithubRepositoryWebhook_ -timeout 120m
=== RUN   TestAccGithubRepositoryWebhook_basic
--- PASS: TestAccGithubRepositoryWebhook_basic (6.25s)
=== RUN   TestAccGithubRepositoryWebhook_secret
--- PASS: TestAccGithubRepositoryWebhook_secret (3.80s)
=== RUN   TestAccGithubRepositoryWebhook_importBasic
--- PASS: TestAccGithubRepositoryWebhook_importBasic (4.94s)
=== RUN   TestAccGithubRepositoryWebhook_importSecret
--- PASS: TestAccGithubRepositoryWebhook_importSecret (5.05s)
PASS
ok  	github.com/terraform-providers/terraform-provider-github/github	20.069s

@radeksimko radeksimko added the Type: Bug Something isn't working as documented label Aug 13, 2018
Copy link
Contributor

@appilon appilon left a comment

Choose a reason for hiding this comment

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

Overall approve only one quick suggestion

}

// Write new keys
for k, v := range oldKeys {
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance this could be done all in the previous loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was actually the very first version of this PR 😃until I saw the test intermittently failing as the for loop kept ranging over some new elements which were just added.

Why? https://golang.org/ref/spec#For_range

The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next. If a map entry that has not yet been reached is removed during iteration, the corresponding iteration value will not be produced. If a map entry is created during iteration, that entry may be produced during the iteration or may be skipped. The choice may vary for each entry created and from one iteration to the next.

Short answer: No.

Feel free to have a play yourself: https://play.golang.org/p/Tm1FPyjwd0m 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

ahhhh yes I see now. 👍

Optional: true,
Sensitive: true,
DiffSuppressFunc: func(k, oldV, newV string, d *schema.ResourceData) bool {
maskedSecret := "********"
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't really worked with sensitive attributes, but it feels strange to me for a maskedSecret to ALWAYS be 8 asterisks, is this code robust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub unfortunately doesn't document this, but I assumed it's a static placeholder they just return. Why would/should the API ever return different number of asterisks?

btw. this is unrelated to how we treat sensitive data in the schema via Sensitive, it's more related to how the backend API (GitHub in this case) implements it.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, I think a code comment might be appropriate in this case mentioning it appears to be an undocumented GH api response.

@radeksimko radeksimko merged commit f5e70fa into master Aug 14, 2018
@radeksimko radeksimko deleted the b-repo-webhook branch August 14, 2018 16:00
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
…ebhook

resource/github_repository_webhook: Avoid spurious diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants