-
Notifications
You must be signed in to change notification settings - Fork 67
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: panic using project_verisoning_strategy without donorpackage #859
Conversation
The Template and DonorPackage are mutually exclusive options, but this isn't reflected in the schema or our internal translation logic between TF State and API Resources. Update the mapping logic to account for DonorPackage sometimes being null. Fixes #855
[sc-102624] |
The schema validation on octopusdeploy_project_verisoning_strategy doesn't match what Octopus Server actually requires. The template and donor_package attributes should be mutually exclusive; donor_package shouldn't always be required. This change: - Adds an EntitySchemaWithResourceValidators interface - Implements this for Project Version Strategy - Makes schema attributes template, donor_package, donor_package_step_id all optional - Makes child attributes of donor_package required, if it's being specified - Validates that either one of template OR donor_package is used - Validates that donor_package and donor_package_step_id must occur together - Makes space_id optional, allowing fallback to the provider configured SpaceId like other resources
if !(state.DonorPackageStepID.IsNull()) { | ||
projectVersioningStrategy.DonorPackageStepID = state.DonorPackageStepID.ValueStringPointer() | ||
} | ||
if !(state.DonorPackage == nil) { |
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 am guessing you do this to match the above line over != nil?
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.
Yeah, consistency of... polarity?... of the check, so that it's easy to scan down and understand. I would've preferred an IsNull()
method, but it doesn't exist on the DonorPackage
struct versus the String above.
func (p ProjectVersioningStrategySchema) GetResourceConfigValidators() []resource.ConfigValidator { | ||
return []resource.ConfigValidator{ | ||
resourcevalidator.RequiredTogether( | ||
path.MatchRoot("donor_package"), | ||
path.MatchRoot("donor_package_step_id"), | ||
), | ||
resourcevalidator.Conflicting( | ||
path.MatchRoot("template"), | ||
path.MatchRoot("donor_package"), | ||
), | ||
resourcevalidator.Conflicting( | ||
path.MatchRoot("template"), | ||
path.MatchRoot("donor_package_step_id"), | ||
), | ||
} | ||
} |
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 Template and DonorPackage on a Project Versioning Strategy are mutually exclusive options, but this isn't reflected in the schema or our internal translation logic between TF State and API Resources.
Our mapping logic between the TF State and the API Resource didn't account for this, which causes #855 - the provider works fine if the
donor_package
approach is used, but crashes if thetemplate
approach is used.I took the opportunity to also fix up the schema, validation, docs and examples to better represent the actual valid inputs from the Octopus Server perspective:
donor_package
in the schema from Required to Optionaldonor_package
to be required, whendonor_package
is presentdonor_package
anddonor_package_step_id
must be present togethertemplate
ordonor_package
can be usedFixes #855
Note: These updates are not a breaking change, because even though it was previously possible from a TF perspective to specify both
donor_package
andtemplate
in a config, Octopus Server API has a server-side check that prevents such a strategy from being applied, and fails theterraform apply
, so it's not possible for any customers to have a config that will break with this change. If that server-side check hadn't existed, we would have had to mark this as breaking due to the stricter requirements on the mutual-exclusivity.