Skip to content

Commit 15985a9

Browse files
committed
Address a few bugs
Signed-off-by: Kobi Samoray <[email protected]>
1 parent 131fb99 commit 15985a9

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

Diff for: nsxt/data_source_nsxt_policy_context_profile_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestAccDataSourceNsxtPolicyContextProfile_multitenancyProvider(t *testing.T
8383
resource.ParallelTest(t, resource.TestCase{
8484
PreCheck: func() {
8585
testAccPreCheck(t)
86-
testAccOnlyMultitenancy(t)
86+
testAccOnlyMultitenancyProvider(t)
8787
},
8888
Providers: testAccProviders,
8989
Steps: []resource.TestStep{
@@ -111,7 +111,7 @@ func testAccNsxtPolicyContextProfileMultitenancyTemplate(name string, withContex
111111
if withContext {
112112
context = testAccNsxtPolicyMultitenancyContext()
113113
}
114-
return fmt.Sprintf(`
114+
s := fmt.Sprintf(`
115115
resource "nsxt_policy_context_profile" "test" {
116116
%s
117117
display_name = "%s"
@@ -133,4 +133,5 @@ data "nsxt_policy_context_profile" "test" {
133133
%s
134134
display_name = nsxt_policy_context_profile.test.display_name
135135
}`, context, name, context)
136+
return s
136137
}

Diff for: nsxt/provider.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,18 @@ func Provider() *schema.Provider {
243243
Description: "Avoid initializing NSX connection on startup",
244244
DefaultFunc: schema.EnvDefaultFunc("NSXT_ON_DEMAND_CONNECTION", false),
245245
},
246-
"context": getContextSchema(false, false, true),
246+
"project_id": {
247+
Type: schema.TypeString,
248+
Description: "Id of the project which the plan executes in its context.",
249+
Optional: true,
250+
DefaultFunc: schema.EnvDefaultFunc("NSXT_PROVIDER_PROJECT_ID", ""),
251+
},
252+
"vpc_id": {
253+
Type: schema.TypeString,
254+
Description: "Id of the VPC which the plan executes in its context.",
255+
Optional: true,
256+
DefaultFunc: schema.EnvDefaultFunc("NSXT_PROVIDER_VPC_ID", ""),
257+
},
247258
},
248259

249260
DataSourcesMap: map[string]*schema.Resource{
@@ -785,10 +796,8 @@ func configurePolicyConnectorData(d *schema.ResourceData, clients *nsxtClients)
785796
clientAuthDefined := (len(clientAuthCertFile) > 0) || (len(clientAuthCert) > 0)
786797
policyEnforcementPoint := d.Get("enforcement_point").(string)
787798
policyGlobalManager := d.Get("global_manager").(bool)
788-
projectID, vpcID, err := getContextDataFromSchema(d, *clients)
789-
if err != nil {
790-
return err
791-
}
799+
projectID := d.Get("project_id").(string)
800+
vpcID := d.Get("vpc_id").(string)
792801
vmcInfo := getVmcAuthInfo(d)
793802

794803
isVMC := false
@@ -1221,10 +1230,10 @@ func getGlobalPolicyEnforcementPointPath(m interface{}, sitePath *string) string
12211230
func getContextDataFromSchema(d *schema.ResourceData, m interface{}) (string, string, error) {
12221231
ctxPtr := d.Get("context")
12231232
if ctxPtr != nil {
1224-
if m.(nsxtClients).ProjectID != "" || m.(nsxtClients).VPCID != "" {
1233+
contexts := ctxPtr.([]interface{})
1234+
if (m.(nsxtClients).ProjectID != "" || m.(nsxtClients).VPCID != "") && len(contexts) > 0 {
12251235
return "", "", fmt.Errorf("cannot specify context in both provider level and object level")
12261236
}
1227-
contexts := ctxPtr.([]interface{})
12281237
for _, context := range contexts {
12291238
data := context.(map[string]interface{})
12301239
vpcID := ""

Diff for: nsxt/utils.go

-8
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,6 @@ func handlePagination(lister func(*paginationInfo) error) (int64, error) {
681681
}
682682

683683
func getContextSchema(isRequired, isComputed, isVPC bool) *schema.Schema {
684-
return getContextExtendedSchema(isRequired, isComputed, isVPC, false)
685-
}
686-
687-
func getContextExtendedSchema(isRequired, isComputed, isVPC, isProvider bool) *schema.Schema {
688684
elemSchema := map[string]*schema.Schema{
689685
"project_id": {
690686
Type: schema.TypeString,
@@ -703,10 +699,6 @@ func getContextExtendedSchema(isRequired, isComputed, isVPC, isProvider bool) *s
703699
ValidateFunc: validation.StringIsNotWhiteSpace,
704700
}
705701
}
706-
if isProvider {
707-
elemSchema["project_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_PROJECT_ID", false)
708-
elemSchema["vpc_id"].DefaultFunc = schema.EnvDefaultFunc("NSXT_PROVIDER_VPC_ID", false)
709-
}
710702
return &schema.Schema{
711703
Type: schema.TypeList,
712704
Description: "Resource context",

Diff for: website/docs/index.html.markdown

+2-3
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,8 @@ The following arguments are used to configure the VMware NSX-T Provider:
251251
for VMC environments, and is not supported with deprecated NSX manager resources and
252252
data sources. Note - this setting is useful when NSX manager is not yet available at
253253
time of provider evaluation, and not recommended to be turned on otherwise.
254-
* `context` - (Optional) The context which the object belongs to
255-
* `project_id` - (Optional) The ID of the project which the object belongs to
256-
* `vpc_id` - (Optional) The ID of the VPC which the object belongs to
254+
* `project_id` - (Optional) ID of the project which the plan executes in its context.
255+
* `vpc_id` - (Optional) ID of the VPC which the plan executes in its context.
257256

258257
## NSX Logical Networking
259258

0 commit comments

Comments
 (0)