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

fix: panic using project_verisoning_strategy without donorpackage #859

Merged
merged 4 commits into from
Feb 6, 2025

Conversation

mjhilton
Copy link
Contributor

@mjhilton mjhilton commented Feb 6, 2025

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 the template 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:

  • Changed donor_package in the schema from Required to Optional
  • Changed child attributes of donor_package to be required, when donor_package is present
  • Added new validation that checks that:
    1. Both donor_package and donor_package_step_id must be present together
    2. Only one of template or donor_package can be used
  • Updated documentation with clearer examples of the two approaches

Fixes #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 and template in a config, Octopus Server API has a server-side check that prevents such a strategy from being applied, and fails the terraform 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.

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
@mjhilton
Copy link
Contributor Author

mjhilton commented Feb 6, 2025

[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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +58 to +73
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"),
),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🆒

@mjhilton mjhilton merged commit 3ea3267 into main Feb 6, 2025
24 checks passed
@mjhilton mjhilton deleted the matth/855-project-verisoning-strategy-panic branch February 6, 2025 05:38
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.

Provider crash when creating a octopusdeploy_project_versioning_strategy resource
2 participants