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

Improve VM Placement Policy data source for tenant users #948

Closed

Conversation

adambarreiro
Copy link
Collaborator

@adambarreiro adambarreiro commented Dec 1, 2022

Overview

This PR modifies the vcd_vm_placement_policy data source to add a new attribute: vdc_id. This attribute helps tenant users to fetch VM Placement Policies, as they cannot obtain provider_vdc_id in any way.

With vdc_id, they can obtain the VDC identifier from the desired VDC and obtain the assigned VM Placement Policies. If the policies are not assigned, this data source will not find them (which makes sense even looking in UI).

As this PR bumps latest Go SDK, in this library it is included a fix that avoids an error when the Provider VDC is backed by many Resource pools (see vmware/go-vcloud-director#530).

Detailed changes

  • provider_vdc_id is now optional and conflicts with vdc_id
  • vdc_id is a new optional attribute that conflicts with provider_vdc_id
  • Improved the filtering by adding policyType==VdcVmPolicy (this one is from v2.0.0 endpoint),isSizingOnly==false and the vGPU policy filter. Not having these options could have lead to bugs in future.
  • Improved error handling. There were also some d.SetId("") which didn't make much sense as the ID was already "" in that conditional branch.
  • Improved documentation to add an example for bot System administrators and tenant users.

Side changes

  • Applied the boy scout rule to fix some broken links in documentation :)
  • Prepare files for v3.8.1

Tests

Improved TestAccVcdVmPlacementPolicy to use the VDC data source (more realistic scenario) and created TestAccVcdVmPlacementPolicyInVdc to test the new scenario, partially (as it is run as System Administrator due to the need of creating admin resources, see the test docs for more).

A manual test of vcd_vm_placement_policy using only a tenant user is required.

  • TestAccVcdVmPlacementPolicy and TestAccVcdVmPlacementPolicyInVdc pass
  • data.vcd_vm_placement_policy using only a tenant user:
provider "vcd" {
  user                 = "foo"
  password             = "*****"
  auth_type            = "integrated"
  url                  = "*****"
  org                  = "test"
  vdc                  = "vdc-test"
  allow_unverified_ssl = true
}

data "vcd_org_vdc" "org-vdc" {
  org      = "test"
  name     = "vdc-test"
}

data "vcd_vm_placement_policy" "policy" {
  name   = "policy1"
  vdc_id = data.vcd_org_vdc.org-vdc.id
}

Note: policy1 was created and assigned to VDC beforehand

  • data.vcd_vm_placement_policy with no vdc_id nor provider_vdc_id set returns Error: either provider_vdc_id or vdc_id needs to be set

Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
go.mod Outdated
@@ -59,3 +59,5 @@ require (
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/adambarreiro/go-vcloud-director/v2 v2.17.0-alpha.1.0.20221201150414-93ae0f2f6136
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this module replacement before you merge this PR,
once you completely finish your code changes and the PR is ready to be merged.
You don't need to resolve this conversation, it will be automatically removed once
go.mod is in a correct state.
Thanks! 😸

Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
@adambarreiro adambarreiro self-assigned this Dec 1, 2022
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
@adambarreiro adambarreiro marked this pull request as ready for review December 1, 2022 17:12
Signed-off-by: abarreiro <abarreiro@vmware.com>
vcd/datasource_vcd_vm_placement_policy.go Outdated Show resolved Hide resolved
vcd/datasource_vcd_vm_placement_policy.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vm_placement_policy.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vm_placement_policy.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vm_placement_policy.go Outdated Show resolved Hide resolved
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
## Argument Reference

The following arguments are supported:

* `name` - (Required) The name VM Placement Policy.
* `provider_vdc_id` - (Required) The ID of the [Provider VDC](/providers/vmware/vcd/latest/docs/data-sources/vcd_provider_vdc) to which the VM Placement Policy belongs.
* `provider_vdc_id` - (Required for System admins) The ID of the [Provider VDC](/providers/vmware/vcd/latest/docs/data-sources/provider_vdc) to which the VM Placement Policy belongs.
* `vdc_id` - (Required for tenant users; *v3.8.1+*) The ID of the [VDC](/providers/vmware/vcd/latest/docs/data-sources/org_vdc) to which the VM Placement Policy is assigned.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a generic question/suggestion about "tenant" vs. "org" term across the whole PR docs. Should we use "org users" instead of "tenant users"?

E.g. here:

Suggested change
* `vdc_id` - (Required for tenant users; *v3.8.1+*) The ID of the [VDC](/providers/vmware/vcd/latest/docs/data-sources/org_vdc) to which the VM Placement Policy is assigned.
* `vdc_id` - (Required for Org users; *v3.8.1+*) The ID of the [VDC](/providers/vmware/vcd/latest/docs/data-sources/org_vdc) to which the VM Placement Policy is assigned.

The thought behind this is that "tenant" is more a business term, while inside the CD itself we see "organization".

Comments are welcome!
CC: @dataclouder @Didainius

Copy link
Collaborator

Choose a reason for hiding this comment

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

Either we use provider/tenant (as it is sometimes appropriate for wide operations guide) or we use System administrator/Org user.
While I have found the provider/tenant pair clearer in some contexts, I think that in this case it should be Org users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that we could use provider/tenant in "soft" text, while in technical docs we should use System administrrator/Org user.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We had to fork this PR so that we can resolve conflicts and merge it therefore the resolution is in PR #953 commit 1f7897c

@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@adambarreiro, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <john.doe@email.org> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Didainius added a commit to Didainius/terraform-provider-vcd that referenced this pull request Dec 7, 2022
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
@Didainius
Copy link
Collaborator

Closing in favor of #953 as we need to merge conflicts while @adambarreiro is away

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.

None yet

6 participants