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

Remove validation that causes issue #1216 #1313

Merged
merged 3 commits into from
Sep 3, 2024

Conversation

adambarreiro
Copy link
Collaborator

@adambarreiro adambarreiro commented Aug 30, 2024

Problem

As it is now, the VCD Provider requires that default_compute_policy_id is set when vm_placement_policy_ids or vm_sizing_policy_ids are specified.

This works for most of the cases, except one important one: When a VDC is created with several Placement policies assigned (vm_placement_policy_ids) but one wants to use the System default Sizing policy as default:

resource "vcd_org_vdc" "TestAccVcdOrgVdcWithAllComputePolicies" {
  # ...omitted

  default_compute_policy_id = null # This will be computed to the System default policy, auto-generated from VCD
  vm_placement_policy_ids   = [
    vcd_vm_placement_policy.placement1.id,
    vcd_vm_placement_policy.placement2.id,
    vcd_vm_placement_policy.placement3.id,
    # ...
  ]
}

Applying a configuration like this will fail on runtime due to a validation the provider does in code:

!contains(vmComputePolicyIds, defaultPolicyId.(string))

Fix

When there is no default_compute_policy_id set (or it is ""), ignore the validation:

defaultPolicyId.(string) != "" && !contains(vmComputePolicyIds, defaultPolicyId.(string))

Tests

Added a new VDC definition that replicates this scenario in TestAccVcdOrgVdcWithAllComputePolicies


Closes #1216

Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro self-assigned this Aug 30, 2024
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as ready for review September 2, 2024 12:40
@adambarreiro
Copy link
Collaborator Author

vm tests passed

Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

Few clarification suggestions inline.

.changes/v3.14.0/1313-bug-fixes.md Outdated Show resolved Hide resolved
vcd/resource_vcd_org_vdc.go Show resolved Hide resolved
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro merged commit 5be3ac1 into vmware:main Sep 3, 2024
2 checks passed
@adambarreiro adambarreiro deleted the compute-policies branch September 3, 2024 12:06
@carmine73
Copy link

To avoid errors on reapply vm_sizing_policy_ids must be set to null or omitted (sorry for this comment, probably it is useful only for me).

resource "vcd_org_vdc" "TestAccVcdOrgVdcWithAllComputePolicies" {
  # ...omitted

  default_compute_policy_id = null # This will be computed to the System default policy, auto-generated from VCD
  vm_sizing_policy_ids      = null # cannot be [], otherwise leads to an error on re-apply
  vm_placement_policy_ids   = []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants