Skip to content

Commit

Permalink
Add custom_url_partial_match to context profile
Browse files Browse the repository at this point in the history
Context profile attributes are missing custom_url_partial_match field
which was added in NSX 4.0

Signed-off-by: Kobi Samoray <ksamoray@vmware.com>
  • Loading branch information
ksamoray committed Apr 4, 2023
1 parent d1796a8 commit af768df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
31 changes: 30 additions & 1 deletion nsxt/resource_nsxt_policy_context_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func resourceNsxtPolicyContextProfile() *schema.Resource {
"revision": getRevisionSchema(),
"tag": getTagsSchema(),
"app_id": getContextProfilePolicyAppIDAttributesSchema(),
"custom_url": getContextProfilePolicyOtherAttributesSchema(),
"custom_url": getContextProfilePolicyCustomURLAttributesSchema(),
"domain_name": getContextProfilePolicyOtherAttributesSchema(),
"url_category": getContextProfilePolicyOtherAttributesSchema(),
},
Expand Down Expand Up @@ -96,6 +96,33 @@ func getContextProfilePolicyAppIDAttributesSchema() *schema.Schema {
}
}

func getContextProfilePolicyCustomURLAttributesSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"description": getDescriptionSchema(),
"value": {
Type: schema.TypeSet,
Description: "Values for attribute key",
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"custom_url_partial_match": {
Type: schema.TypeBool,
Description: "True value for this flag will be treated as a partial match for custom url",
Optional: true,
Default: true,
},
},
},
}
}

func getContextProfilePolicyOtherAttributesSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Expand Down Expand Up @@ -514,6 +541,8 @@ func fillAttributesInSchema(d *schema.ResourceData, policyAttributes []model.Pol
elem["sub_attribute"] = fillSubAttributesInSchema(policyAttribute.SubAttributes)
}
elem["is_alg_type"] = policyAttribute.IsALGType
} else if *policyAttribute.Key == model.PolicyAttributes_KEY_CUSTOM_URL && nsxVersionHigherOrEqual("4.0.0") {
elem["custom_url_partial_match"] = policyAttribute.CustomUrlPartialMatch
}
attributes[key] = append(attributes[key], elem)
}
Expand Down
4 changes: 4 additions & 0 deletions nsxt/resource_nsxt_policy_context_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestAccResourceNsxtPolicyContextProfile_multipleAttributes(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "domain_name.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "url_category.#", "0"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.is_alg_type"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.custom_url_partial_match"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.#", "3"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.0", "HTTP"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.1", "SSH"),
Expand Down Expand Up @@ -214,6 +215,7 @@ func TestAccResourceNsxtPolicyContextProfile_subAttributes(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "domain_name.#", "0"),
resource.TestCheckResourceAttr(testResourceName, "url_category.#", "0"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.is_alg_type"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.custom_url_partial_match"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.0", "SSL"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.sub_attribute.#", "1"),
Expand All @@ -239,6 +241,7 @@ func TestAccResourceNsxtPolicyContextProfile_subAttributes(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "domain_name.#", "0"),
resource.TestCheckResourceAttr(testResourceName, "url_category.#", "0"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.is_alg_type"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.custom_url_partial_match"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.0", "CIFS"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.sub_attribute.#", "1"),
Expand All @@ -265,6 +268,7 @@ func TestAccResourceNsxtPolicyContextProfile_subAttributes(t *testing.T) {
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.#", "1"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.value.0", "SSL"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.is_alg_type"),
resource.TestCheckResourceAttrSet(testResourceName, "app_id.0.custom_url_partial_match"),
resource.TestCheckResourceAttr(testResourceName, "app_id.0.sub_attribute.#", "0"),
),
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/policy_context_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ In addition to arguments listed above, the following attributes are exported:
* `path` - The NSX path of the policy resource.
* `app_id`:
* `is_alg_type` - Describes whether the APP_ID value is ALG type or not.
* `custom_url_partial_match` - True value for this flag will be treated as a partial match for custom url. Attribute is supported with NSX version 4.0.0 and above.

## Importing

Expand Down

0 comments on commit af768df

Please sign in to comment.