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

CC-30971: update state with allowlist api responses #258

Conversation

fantapop
Copy link
Collaborator

@fantapop fantapop commented Jan 15, 2025

Previously the object the api returned for created and updated allowlist entries was ignored when updating the terraform state. This meant that defaults set on the server side and returned were not correctly being set and could cause state inconsistencies in case they were different. Specifically there was a case where not setting an initial value for the create would return an empty string. The empty string caused a state consistency error with the unset value.
To fix this we now set the state based on the response. Also, part of this the code was reworked to be more similar to how other resources are structured.

Tests were added to show that creating an allowlist without a name now succeeds.

Also, as part of this change, instances of allowList were renamed to allowlist for consistency.

Commit checklist

  • Changelog
  • Doc gen (make generate)
  • Integration test(s)
  • Acceptance test(s)
  • Example(s)

Description: "Name of this allowlist entry. If not set explicitly, this value does not sync with the server.",
Description: "Name of this allowlist entry. If left unset, it will inherit a server side default.",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kathancox just a little bit of docs change here if you could take a peak! ty

return fmt.Sprintf(allowlistIDFmt, clusterID, cidrIP, cidrMask)
}

func loadAllowlistEntryToTerraformState(clusterID string, entry *client.AllowlistEntry, state *AllowlistEntry) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why this isn't more like a "transformToState" function with a signature like

(string, *client.AllowlistEntry) -> (*AllowlistEntry)

?

I might be missing it but do we get something from passing in the state param instead of making this a pure function?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah because other uses besides create already come with a state I guess. In those cases though it seems like we throw away the old state anyway, so we could always do something like

*state = *transformToState(clusterID, entry)

Maybe this is just following a pattern we use all over even if in a vacuum there may be a better solution. That seems fine to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've generally just been following the pattern that was existing but I think you're probably right about why this pattern started. I think it would be cleaner to do as you suggest. It would also be nice to separate each resource into it's own package or create an interface which allows us to stop fully qualifying all the function names. i.e loadAllowlistEntryToTerraformState -> r.transformToState

Copy link
Contributor

@rgcase rgcase left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@kathancox kathancox left a comment

Choose a reason for hiding this comment

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

LGTM, one small, non-blocking suggestion!

@@ -36,7 +36,7 @@ resource "cockroach_allow_list" "vpn" {

### Optional

- `name` (String) Name of this allowlist entry. If not set explicitly, this value does not sync with the server.
- `name` (String) Name of this allowlist entry. If left unset, it will inherit a server side default.

Choose a reason for hiding this comment

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

Suggested change
- `name` (String) Name of this allowlist entry. If left unset, it will inherit a server side default.
- `name` (String) Name of this allowlist entry. If left unset, it will inherit a server-side default.

@fantapop fantapop force-pushed the CC-30971-unnamed-allowlist-causes-terraform-state-inconsistency-error branch 2 times, most recently from fe70889 to 084151e Compare January 15, 2025 18:30
Previously the object the api returned for created and updated allowlist
entries was ignored when updating the terraform state.  This meant that
defaults set on the server side and returned were not correctly being
set and could cause state inconsistencies in case they were different.
Specifically there was a case where not setting an initial value for the
create would return an empty string.  The empty string caused a state
consistency error with the unset value.
To fix this we now set the state based on the response.  As part of this
the code was reworked to be more similar to how other resources are
structured.

Tests were added to show that creating an allowlist without a name now
succeeds.

Also, as part of this change, instances of allowList were renamed to
allowlist for consistency.
The image in use for our ci actions, ubuntu-latest is now defaulting to
ubuntu-24.04.  In the previous version, terraform was installed by
default but has now been removed so we install it manually for each job
that relies on it.

actions/runner-images#10636

We choose not to pin the version of terraform that is installed so we
are always testing against the the latest CLI version. If there is a
discrepancy between versions that only affects tests, developers can
update to the latest version and ensure the tests work for that.
@fantapop fantapop force-pushed the CC-30971-unnamed-allowlist-causes-terraform-state-inconsistency-error branch from 084151e to 81f2de2 Compare January 15, 2025 20:39
@fantapop fantapop merged commit abfdd63 into main Jan 15, 2025
4 checks passed
@fantapop fantapop deleted the CC-30971-unnamed-allowlist-causes-terraform-state-inconsistency-error branch January 15, 2025 22:43
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.

3 participants