Skip to content

Commit

Permalink
Address a few bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Jun 10, 2024
1 parent 131fb99 commit 15985a9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
5 changes: 3 additions & 2 deletions nsxt/data_source_nsxt_policy_context_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestAccDataSourceNsxtPolicyContextProfile_multitenancyProvider(t *testing.T
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccOnlyMultitenancy(t)
testAccOnlyMultitenancyProvider(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -111,7 +111,7 @@ func testAccNsxtPolicyContextProfileMultitenancyTemplate(name string, withContex
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
}
return fmt.Sprintf(`
s := fmt.Sprintf(`
resource "nsxt_policy_context_profile" "test" {
%s
display_name = "%s"
Expand All @@ -133,4 +133,5 @@ data "nsxt_policy_context_profile" "test" {
%s
display_name = nsxt_policy_context_profile.test.display_name
}`, context, name, context)
return s
}
23 changes: 16 additions & 7 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,18 @@ func Provider() *schema.Provider {
Description: "Avoid initializing NSX connection on startup",
DefaultFunc: schema.EnvDefaultFunc("NSXT_ON_DEMAND_CONNECTION", false),
},
"context": getContextSchema(false, false, true),
"project_id": {
Type: schema.TypeString,
Description: "Id of the project which the plan executes in its context.",
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NSXT_PROVIDER_PROJECT_ID", ""),
},
"vpc_id": {
Type: schema.TypeString,
Description: "Id of the VPC which the plan executes in its context.",
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NSXT_PROVIDER_VPC_ID", ""),
},
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -785,10 +796,8 @@ func configurePolicyConnectorData(d *schema.ResourceData, clients *nsxtClients)
clientAuthDefined := (len(clientAuthCertFile) > 0) || (len(clientAuthCert) > 0)
policyEnforcementPoint := d.Get("enforcement_point").(string)
policyGlobalManager := d.Get("global_manager").(bool)
projectID, vpcID, err := getContextDataFromSchema(d, *clients)
if err != nil {
return err
}
projectID := d.Get("project_id").(string)
vpcID := d.Get("vpc_id").(string)
vmcInfo := getVmcAuthInfo(d)

isVMC := false
Expand Down Expand Up @@ -1221,10 +1230,10 @@ func getGlobalPolicyEnforcementPointPath(m interface{}, sitePath *string) string
func getContextDataFromSchema(d *schema.ResourceData, m interface{}) (string, string, error) {
ctxPtr := d.Get("context")
if ctxPtr != nil {
if m.(nsxtClients).ProjectID != "" || m.(nsxtClients).VPCID != "" {
contexts := ctxPtr.([]interface{})
if (m.(nsxtClients).ProjectID != "" || m.(nsxtClients).VPCID != "") && len(contexts) > 0 {
return "", "", fmt.Errorf("cannot specify context in both provider level and object level")
}
contexts := ctxPtr.([]interface{})
for _, context := range contexts {
data := context.(map[string]interface{})
vpcID := ""
Expand Down
8 changes: 0 additions & 8 deletions nsxt/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,6 @@ func handlePagination(lister func(*paginationInfo) error) (int64, error) {
}

func getContextSchema(isRequired, isComputed, isVPC bool) *schema.Schema {
return getContextExtendedSchema(isRequired, isComputed, isVPC, false)
}

func getContextExtendedSchema(isRequired, isComputed, isVPC, isProvider bool) *schema.Schema {
elemSchema := map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand All @@ -703,10 +699,6 @@ func getContextExtendedSchema(isRequired, isComputed, isVPC, isProvider bool) *s
ValidateFunc: validation.StringIsNotWhiteSpace,
}
}
if isProvider {
elemSchema["project_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_PROJECT_ID", false)
elemSchema["vpc_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_VPC_ID", false)
}
return &schema.Schema{
Type: schema.TypeList,
Description: "Resource context",
Expand Down
5 changes: 2 additions & 3 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ The following arguments are used to configure the VMware NSX-T Provider:
for VMC environments, and is not supported with deprecated NSX manager resources and
data sources. Note - this setting is useful when NSX manager is not yet available at
time of provider evaluation, and not recommended to be turned on otherwise.
* `context` - (Optional) The context which the object belongs to
* `project_id` - (Optional) The ID of the project which the object belongs to
* `vpc_id` - (Optional) The ID of the VPC which the object belongs to
* `project_id` - (Optional) ID of the project which the plan executes in its context.
* `vpc_id` - (Optional) ID of the VPC which the plan executes in its context.

## NSX Logical Networking

Expand Down

0 comments on commit 15985a9

Please sign in to comment.