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

Implement policy site resource #1104

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Conversation

ksamoray
Copy link
Collaborator

@ksamoray ksamoray commented Feb 8, 2024

No description provided.

@ksamoray ksamoray force-pushed the resource_site branch 2 times, most recently from a40097f to 4d2dbad Compare February 11, 2024 13:34
@ksamoray ksamoray changed the title [WIP]: Implement policy site resource Implement policy site resource Feb 11, 2024
@ksamoray ksamoray force-pushed the resource_site branch 2 times, most recently from 23c7c76 to fc76f7d Compare February 11, 2024 13:51
@salv-orlando salv-orlando added this to the v3.6.0 milestone Feb 12, 2024
}

func resourceNsxtPolicySiteCreate(d *schema.ResourceData, m interface{}) error {
id, err := getOrGenerateID(d, m, resourceNsxtPolicySiteExists)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add here:
if !isPolicyGlobalManager(m) {
return globalManagerOnlyError()
}

Type: schema.TypeString,
Optional: true,
Description: "Persistent Site Type",
ValidateFunc: validation.StringInSlice(siteTypeValues, false),
Copy link
Collaborator

Choose a reason for hiding this comment

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

No default here? What happens if this is unspecified? Should the value be Computed in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Spec doesn't specify a default here.
As UI in GM allows only on-prem addition, maybe we could discard this attribute entirely?
Screenshot 2024-02-15 at 12 10 55

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this depends on env, and perhaps default depends on env as well. If NSX auto-assigns this value, we can define it as Computed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turns out this this is required...

│ Error:  Failed to create Site f5bb6846-cf9d-4efd-9cd6-4d11de593fff: Field level validation errors: {value  of property site_type is not one of the allowed values [ONPREM_LM, SDDC_LM]} (code 255)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe no need to set a default for now.
Let's try and understand better the use cases around SDDC_LM. If ONPREM_LM is used in 99% of cases, then we can set if as default in a follow-up PR.

@ksamoray ksamoray force-pushed the resource_site branch 5 times, most recently from 9611ac5 to 3c23ddb Compare February 20, 2024 18:25
* `site_uuid` - (Optional) ID of Site.
* `thumbprint` - (Optional) Thumbprint of Enforcement Point.
* `username` - (Optional) Username.
* `site_type` - (Required) Persistent Site Type. Allowed values are ONPREM_LM, SDDC_LM. Default is ONPREM_LM.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't have a default according to the code (and its Required). Also lets surround the values in `` for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's required in the code? The spec doesn't enlist it as so.

Type: schema.TypeString,
Optional: true,
Description: "Persistent Site Type",
ValidateFunc: validation.StringInSlice(siteTypeValues, false),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe no need to set a default for now.
Let's try and understand better the use cases around SDDC_LM. If ONPREM_LM is used in 99% of cases, then we can set if as default in a follow-up PR.

State: nsxtPolicyPathResourceImporter,
},

Schema: map[string]*schema.Schema{
Copy link
Member

Choose a reason for hiding this comment

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

do you think site_number might be useful as a computed attribute?

Looking at the API spec, do you think we should include FederationConfig, remote_path, relative_path as computed too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haven't found use for those yet, usually we add read-only attrs only if they're used as reference anywhere else or just seem very useful. As I haven't complete yet the federation object implementation, I might find their use later on maybe. Anyway it's always easier to add attributes than removing them.

var tags []gm_model.Tag
tagListIntface := d.Get("tag")
if tagListIntface != nil {
tagList := tagListIntface.(*schema.Set).List()
Copy link
Member

Choose a reason for hiding this comment

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

I might be wrong, but didn't we have util method for doing this process?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have more than one utility, as the SDK has different model.Tag structs for policy/MP/GM APIs. However there's no util func for GM - I could add one or convert to policy model and then use TypeConverter (we do this when there's a resource which runs for both M and policy).

connector := getPolicyConnector(m)
client := global_infra.NewSitesClient(connector)

obj := getSiteFromSchema(d)
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me the behaviour that NSX will have if the update site_connection_info.
Did we test 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.

I didn't try to set it (I need an extra LM to test this). But connectivity info is updatable in UI.

* `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource.
* `fail_if_rtep_misconfigured` - (Optional) Fail onboarding if RTEPs misconfigured. Default is true.
* `fail_if_rtt_exceeded` - (Optional) Fail onboarding if maximum RTT exceeded. Default is true.
* `maximum_rtt` - (Optional) Maximum acceptable packet round trip time (RTT). Default is 250.
Copy link
Member

Choose a reason for hiding this comment

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

The NSX API guide does not mention it, but I think we should specify the unit of measure.
msecs, I believe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IDK which are the units as I couldn't find that attribute in the UI

@ksamoray ksamoray force-pushed the resource_site branch 11 times, most recently from 1355ddc to 6d4fd70 Compare February 27, 2024 19:03
@ksamoray ksamoray merged commit 92278e6 into vmware:master Mar 5, 2024
2 checks passed
@ksamoray ksamoray deleted the resource_site branch March 5, 2024 09:17
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.

3 participants