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

team: mark slug as computed when name changes #757

Merged
merged 3 commits into from
May 7, 2021

Conversation

bendrucker
Copy link
Contributor

@bendrucker bendrucker commented Apr 12, 2021

This configures Terraform to mark github_team.*.slug as computed any time name changes, ensuring that it shows any resource that is dependent on slug as requiring an update.

I spotted this need when using terraform import with an existing team that had a different name than what was declared in configuration. Other resources in the same configuration (team_sync_group_mapping in my case) that depended on that slug still showed the current slug in the plan. Without this hint from CustomizeDiff, Terraform can't know that the computed value of slug will be different after the name is updated and the value in state (from the import) should not be used.

I used customdiff.Sequence as a general pattern here so that additional CustomizeDiffFuncs can be added for other fields. However, it could easily be removed too.

A test that has another resource that depends on slug provides coverage here. Using another team and sticking a slug in the description was convenient. Without the customized diff, the test fails:

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccGithubTeamUpdateName -timeout 120m
?   	github.com/terraform-providers/terraform-provider-github	[no test files]
=== RUN   TestAccGithubTeamUpdateName
=== RUN   TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes
=== RUN   TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes/with_an_anonymous_account
    resource_github_team_test.go:199: anonymous account not supported for this operation
=== RUN   TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes/with_an_individual_account
    resource_github_team_test.go:203: individual account not supported for this operation
=== RUN   TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes/with_an_organization_account
    testing.go:654: Step 1 error: errors during apply:

        Error: Provider produced inconsistent final plan

        When expanding the plan for github_team.other to include new values learned so
        far during apply, provider "github" produced an invalid new value for
        .description: was cty.StringVal("tf-acc-kpzaa"), but now
        cty.StringVal("tf-acc-updated-kpzaa").

        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.

--- FAIL: TestAccGithubTeamUpdateName (8.71s)
    --- FAIL: TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes (8.71s)
        --- SKIP: TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes/with_an_anonymous_account (0.00s)
        --- SKIP: TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes/with_an_individual_account (0.00s)
        --- FAIL: TestAccGithubTeamUpdateName/marks_the_slug_as_computed_when_the_name_changes/with_an_organization_account (8.71s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-github/github	8.970s
FAIL
make: *** [testacc] Error 1

With the custom diff the test passes.

@jcudit jcudit modified the milestones: v4.9.0, v4.9.3 Apr 30, 2021
@@ -7,6 +7,7 @@ import (
"strconv"

"github.com/google/go-github/v32/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a neat helper. Thanks for bringing it into the project!

@jcudit jcudit merged commit c9ab58d into integrations:master May 7, 2021
@jcudit
Copy link
Contributor

jcudit commented May 7, 2021

Much appreciation for getting this edge case covered. I feel blind to this use case and am thankful to have contributions like this 🎉

@bendrucker bendrucker deleted the team-slug-diff branch May 7, 2021 19:34
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
* team: mark slug as computed when name changes

* add test

* vendor
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

Successfully merging this pull request may close these issues.

2 participants