-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: use unique template version names #54
fix: use unique template version names #54
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @ethanndickson and the rest of your teammates on Graphite |
docs/resources/template.md
Outdated
@@ -45,14 +45,16 @@ Optional: | |||
|
|||
- `active` (Boolean) Whether this version is the active version of the template. Only one version can be active at a time. | |||
- `message` (String) A message describing the changes in this version of the template. Messages longer than 72 characters will be truncated. | |||
- `name` (String) The name of the template version. Automatically generated if not provided. | |||
- `name_suffix` (String) A suffix for the name of the template version. Prepended by a random string. Must be unique within the list of versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix feels more intuitive to me, like myversion-2-a3458b
rather than a3458b-2-myversion
, that way if you sort lexicographically you get a sensible outcome.
I think it should be prefix-ordinal-randomstring
if you include a prefix, and if you don't include a prefix we should submit without a name and let Coderd do the picking of a random name. The way you have it now, if you don't have this set you get something like 1_stuffy_enstein4
followed by 2_watery_tart6
, which seems very strange.
Name: types.StringValue("main"), | ||
Message: types.StringValue("Initial commit"), | ||
Directory: types.StringValue("../../integration/template-test/example-template/"), | ||
NameSuffix: types.StringValue("version-one"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did we change from "main" to "version-one"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming I chose originally was honestly just making it harder to follow the resource tests as I was fixing them. This just reads a bit better, and I updated the data source tests for consistency.
if foundVersion == nil || foundVersion.DirectoryHash != plannedVersion.DirectoryHash { | ||
var curVersionName string | ||
// All versions in the state are guaranteed to have known name suffixes | ||
foundVersion := curState.Versions.ByNameSuffix(plannedVersion.NameSuffix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you not allowed to have multiple versions with an empty suffix? I thought empty suffix is meant to mean, "pick a name for me automatically, I don't care what."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been operating under the assumption that we need something that persists across multiple configurations to be able to figure out what's a new template version, and what's an existing template version that we're updating (because, ultimately we want to avoid the spurious template version diffs).
We can't use the version ID because Terraform sets all computed attributes to Unknown
before it calls Update
. However, they provide you a way to UseStateForUnknown
where it'll read the last value in the state file and use that instead. However, if you do this, the value gets set during the plan, and so if the directory contents change, and trigger the creation of a new template version, we'd get a new version ID. However, since the version ID was set during the plan, Terraform will complain that the value after the apply differed from what was planned. I don't see any way to turn this check off.
Since the NameSuffix
is not computed, and is always specified in the configuration, we can use it as the 'primary key' here. The downside being that we can't have multiple versions with an empty suffix.
Instead we could do something like generate our own Terraform template version ID, and put UseStateForUnknown
on that?
I worry if all the fields in the versions set change, Terraform won't be able to figure out what element is which, but I'd have to mess around with it and see exactly how it persists set elements. Worst case scenario, if you change everything you end up with a new version with no non-metadata changes.
450beaa
to
5ec8b26
Compare
Spike and I have decided to close this fix, in favour of simply allowing users to set the full name of the template version. A future PR will add documentation telling users to not set the |
This fixes a bug where if a template version had it's contents updated, but the template version's name remained the same, the
terraform apply
would fail as the server would reject a template version name collision.Instead, the user supplies a
name_suffix
field that is prepended with the number of revisions using that suffix, and a randomly generated name. The full name of the template version is available atversions.*.full_name
.This PR also fixes a bug where a configured ACL
everyone: use
permission could be deleted and not recovered when the template metadata changes.