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

Add VPC data source #1207

Merged
merged 2 commits into from
May 26, 2024
Merged

Add VPC data source #1207

merged 2 commits into from
May 26, 2024

Conversation

ksamoray
Copy link
Collaborator

No description provided.

@ksamoray
Copy link
Collaborator Author

/test-all

@ksamoray ksamoray force-pushed the ds-vpc branch 2 times, most recently from cddacce to 9cb2338 Compare May 13, 2024 10:50
@ksamoray
Copy link
Collaborator Author

/test-all

return fmt.Errorf("error obtaining VPC ID or name during read")
} else {
// Get by full name/prefix
objList, err := client.List(defaultOrgID, ctx.ProjectID, nil, nil, nil, nil, nil, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Search - to the best of my knowledge - should be working across orgs and projects.
Can we use it here instead of iterating over the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've tried to implement the project datasource with search API at the time, which didn't work. So I didn't even try with this one - maybe it's worthwhile trying.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this support pagination?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced logic with search API

}
}
if len(perfectMatch) > 0 {
if len(perfectMatch) > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

For VPC objects perhaps uniqueness should be defined within a project.
Perhaps we should filter by ctx.projectId and display name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

client.List() call (L55) takes a project parameter, so uniqueness is only checked at the scope of these query results.

resource.TestCheckResourceAttr(testResourceName, "display_name", name),
resource.TestCheckResourceAttr(testResourceName, "description", name),
resource.TestCheckResourceAttrSet(testResourceName, "path"),
//resource.TestCheckResourceAttrSet(testResourceName, "default_gateway_path"),
Copy link
Member

Choose a reason for hiding this comment

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

Why is this attribute commented? Is it giving you troubles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't set the DGW path parameter in Create() (L84), I intended to remove this as although I could gather the T0 id, I had to create a path from it as I do with IP block. It's quite ugly... If you think that there's some importance to this, I can add it.
TBH I'd rather rewrite this once we have a resource for VPC.

"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should project be required here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed

@ksamoray
Copy link
Collaborator Author

/test-all

* `site_info` - Information related to sites applicable for given Project.
* `edge_cluster_paths` - The edge cluster on which the networking elements for the Org will be created.
* `site_path` - This represents the path of the site which is managed by Global Manager. For the local manager, if set, this needs to point to 'default'.
* `default_gateway_path` - The tier 0 has to be pre-created before Project is created.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This description does not seem relevant to data source

* `path` - The NSX path of the policy resource.
* `short_id` - Defaults to id if id is less than equal to 8 characters or defaults to random generated id if not set.
* `site_info` - Information related to sites applicable for given Project.
* `edge_cluster_paths` - The edge cluster on which the networking elements for the Org will be created.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Org => VPC?

* `short_id` - Defaults to id if id is less than equal to 8 characters or defaults to random generated id if not set.
* `site_info` - Information related to sites applicable for given Project.
* `edge_cluster_paths` - The edge cluster on which the networking elements for the Org will be created.
* `site_path` - This represents the path of the site which is managed by Global Manager. For the local manager, if set, this needs to point to 'default'.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is relevant for VPC

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure either - I reused the SiteInfo from Project as these two use the same schema. Should I remove site_path entirely from this DS?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tvigneron could you please give your opinion?


* `id` - (Optional) The ID of VPC to retrieve. If ID is specified, no additional argument should be configured.
* `display_name` - (Optional) The Display Name prefix of the VPC to retrieve.
* `context` - (Optional) The context which the object belongs to
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be Required

"default_gateway_path": getPathSchema(),
"short_id": {
Type: schema.TypeString,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to the code this is fully computed, in which case Optional: true should be removed, so that terraform does not allow user to specify it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This value is assigned by NSX if not set by user, and therefore has to be computed. It can also be set by the user (it should be unique - NSX will enforce that).
The UI doesn't allow updating it (on create there's the text "This field can be set at VPC creation time and cannot be edited later. Max 8 characters allowed.").
BTW there's an open issue for this in the Project.

Signed-off-by: Kobi Samoray <kobi.samoray@broadcom.com>
Signed-off-by: Kobi Samoray <kobi.samoray@broadcom.com>
@ksamoray
Copy link
Collaborator Author

/test-all

@ksamoray ksamoray merged commit 5308952 into vmware:master May 26, 2024
7 checks passed
@ksamoray ksamoray deleted the ds-vpc branch May 26, 2024 09:47
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

3 participants