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

azurerm_vpn_site - support new property o365_policy #16820

Merged
merged 4 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions internal/services/network/vpn_site_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,44 @@ func resourceVpnSite() *pluginsdk.Resource {
},
},

"o365_policy": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"traffic_category": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"allow_endpoint_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"default_endpoint_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"optimize_endpoint_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
},
},
},
},
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -172,6 +210,7 @@ func resourceVpnSiteCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) er
DeviceProperties: expandVpnSiteDeviceProperties(d),
AddressSpace: expandVpnSiteAddressSpace(d.Get("address_cidrs").(*pluginsdk.Set).List()),
VpnSiteLinks: expandVpnSiteLinks(d.Get("link").([]interface{})),
O365Policy: expandVpnSiteO365Policy(d.Get("o365_policy").([]interface{})),
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}
Expand Down Expand Up @@ -244,6 +283,9 @@ func resourceVpnSiteRead(d *pluginsdk.ResourceData, meta interface{}) error {
if err := d.Set("link", flattenVpnSiteLinks(prop.VpnSiteLinks)); err != nil {
return fmt.Errorf("setting `link`")
}
if err := d.Set("o365_policy", flattenVpnSiteO365Policy(prop.O365Policy)); err != nil {
return fmt.Errorf("setting `o365_policy`")
}
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down Expand Up @@ -447,3 +489,75 @@ func flattenVpnSiteVpnSiteBgpSettings(input *network.VpnLinkBgpSettings) []inter
},
}
}

func expandVpnSiteO365Policy(input []interface{}) *network.O365PolicyProperties {
if len(input) == 0 || input[0] == nil {
return nil
}

o365Policy := input[0].(map[string]interface{})

return &network.O365PolicyProperties{
BreakOutCategories: expandVpnSiteO365TrafficCategoryPolicy(o365Policy["traffic_category"].([]interface{})),
}
}

func expandVpnSiteO365TrafficCategoryPolicy(input []interface{}) *network.O365BreakOutCategoryPolicies {
if len(input) == 0 || input[0] == nil {
return nil
}

trafficCategory := input[0].(map[string]interface{})

return &network.O365BreakOutCategoryPolicies{
Allow: utils.Bool(trafficCategory["allow_endpoint_enabled"].(bool)),
Default: utils.Bool(trafficCategory["default_endpoint_enabled"].(bool)),
Optimize: utils.Bool(trafficCategory["optimize_endpoint_enabled"].(bool)),
}
}

func flattenVpnSiteO365Policy(input *network.O365PolicyProperties) []interface{} {
if input == nil {
return []interface{}{}
}

var trafficCategory []interface{}
if input.BreakOutCategories != nil {
trafficCategory = flattenVpnSiteO365TrafficCategoryPolicy(input.BreakOutCategories)
}

return []interface{}{
map[string]interface{}{
"traffic_category": trafficCategory,
},
}
}

func flattenVpnSiteO365TrafficCategoryPolicy(input *network.O365BreakOutCategoryPolicies) []interface{} {
if input == nil {
return []interface{}{}
}

isAllowed := false
if input.Allow != nil {
isAllowed = *input.Allow
}

isDefault := false
if input.Default != nil {
isDefault = *input.Default
}

isOptimized := false
if input.Optimize != nil {
isOptimized = *input.Optimize
}

return []interface{}{
map[string]interface{}{
"allow_endpoint_enabled": isAllowed,
"default_endpoint_enabled": isDefault,
"optimize_endpoint_enabled": isOptimized,
},
}
}
49 changes: 49 additions & 0 deletions internal/services/network/vpn_site_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ func TestAccVpnSite_requiresImport(t *testing.T) {
})
}

func TestAccVpnSite_o365Policy(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_vpn_site", "test")
r := VPNSiteResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.o365Policy(data, true, true, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.o365Policy(data, false, false, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t VPNSiteResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.VpnSiteID(state.ID)
if err != nil {
Expand Down Expand Up @@ -174,6 +196,33 @@ resource "azurerm_vpn_site" "import" {
`, r.basic(data), data.RandomInteger)
}

func (r VPNSiteResource) o365Policy(data acceptance.TestData, allowCategoryEnabled, defaultCategoryEnabled, optimizeCategoryEnabled bool) string {
return fmt.Sprintf(`
%s

resource "azurerm_vpn_site" "test" {
name = "acctest-VpnSite-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
virtual_wan_id = azurerm_virtual_wan.test.id
address_cidrs = ["10.0.0.0/24"]

o365_policy {
traffic_category {
allow_endpoint_enabled = %t
default_endpoint_enabled = %t
optimize_endpoint_enabled = %t
}
}

link {
name = "link1"
ip_address = "10.0.0.1"
}
}
`, r.template(data), data.RandomInteger, allowCategoryEnabled, defaultCategoryEnabled, optimizeCategoryEnabled)
}

func (VPNSiteResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
18 changes: 18 additions & 0 deletions website/docs/r/vpn_site.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The following arguments are supported:

* `device_vendor` - (Optional) The name of the VPN device vendor.

* `o365_policy` - (Optional) An `o365_policy` block as defined below.

* `tags` - (Optional) A mapping of tags which should be assigned to the VPN Site.

---
Expand Down Expand Up @@ -96,6 +98,22 @@ A `link` block supports the following:

* `speed_in_mbps` - (Optional) The speed of the VPN device at the branch location in unit of mbps.

---

A `o365_policy` block supports the following:

* `traffic_category` - (Optional) A `traffic_category` block as defined above.

---

A `traffic_category` block supports the following:

* `allow_endpoint_enabled` - (Optional) Is allow endpoint enabled? The `Allow` endpoint is required for connectivity to specific O365 services and features, but are not as sensitive to network performance and latency as other endpoint types. Defaults to `false`.

* `default_endpoint_enabled` - (Optional) Is default endpoint enabled? The `Default` endpoint represents O365 services and dependencies that do not require any optimization, and can be treated by customer networks as normal Internet bound traffic. Defaults to `false`.

* `optimize_endpoint_enabled` - (Optional) Is optimize endpoint enabled? The `Optimize` endpoint is required for connectivity to every O365 service and represents the O365 scenario that is the most sensitive to network performance, latency, and availability. Defaults to `false`.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand Down