-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
new PR for #3505
- Loading branch information
Showing
6 changed files
with
505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func resourceArmVirtualWan() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmVirtualWanCreateUpdate, | ||
Read: resourceArmVirtualWanRead, | ||
Update: resourceArmVirtualWanCreateUpdate, | ||
Delete: resourceArmVirtualWanDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"location": azure.SchemaLocation(), | ||
|
||
"disable_vpn_encryption": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
|
||
"security_provider_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"allow_branch_to_branch_traffic": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
|
||
"allow_vnet_to_vnet_traffic": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
|
||
"office365_local_breakout_category": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(network.OfficeTrafficCategoryAll), | ||
string(network.OfficeTrafficCategoryNone), | ||
string(network.OfficeTrafficCategoryOptimize), | ||
string(network.OfficeTrafficCategoryOptimizeAndAllow), | ||
}, false), | ||
Default: string(network.OfficeTrafficCategoryNone), | ||
}, | ||
|
||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmVirtualWanCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).network.VirtualWanClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
log.Printf("[INFO] preparing arguments for Virtual WAN creation.") | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
location := azure.NormalizeLocation(d.Get("location").(string)) | ||
disableVpnEncryption := d.Get("disable_vpn_encryption").(bool) | ||
securityProviderName := d.Get("security_provider_name").(string) | ||
allowBranchToBranchTraffic := d.Get("allow_branch_to_branch_traffic").(bool) | ||
allowVnetToVnetTraffic := d.Get("allow_vnet_to_vnet_traffic").(bool) | ||
office365LocalBreakoutCategory := d.Get("office365_local_breakout_category").(string) | ||
tags := d.Get("tags").(map[string]interface{}) | ||
|
||
if requireResourcesToBeImported && d.IsNewResource() { | ||
existing, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return fmt.Errorf("Error checking for presence of existing Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
} | ||
|
||
if existing.ID != nil && *existing.ID != "" { | ||
return tf.ImportAsExistsError("azurerm_virtual_wan", *existing.ID) | ||
} | ||
} | ||
|
||
wan := network.VirtualWAN{ | ||
Location: utils.String(location), | ||
Tags: expandTags(tags), | ||
VirtualWanProperties: &network.VirtualWanProperties{ | ||
DisableVpnEncryption: utils.Bool(disableVpnEncryption), | ||
SecurityProviderName: utils.String(securityProviderName), | ||
AllowBranchToBranchTraffic: utils.Bool(allowBranchToBranchTraffic), | ||
AllowVnetToVnetTraffic: utils.Bool(allowVnetToVnetTraffic), | ||
Office365LocalBreakoutCategory: network.OfficeTrafficCategory(office365LocalBreakoutCategory), | ||
}, | ||
} | ||
|
||
future, err := client.CreateOrUpdate(ctx, resourceGroup, name, wan) | ||
if err != nil { | ||
return fmt.Errorf("Error creating/updating Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("Error waiting for creation/update of Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
read, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read Virtual WAN %q (Resource Group %q) ID", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmVirtualWanRead(d, meta) | ||
} | ||
|
||
func resourceArmVirtualWanRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).network.VirtualWanClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
name := id.Path["virtualWans"] | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
log.Printf("[DEBUG] Virtual WAN %q (Resource Group %q) was not found - removing from state", name, resourceGroup) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azure.NormalizeLocation(*location)) | ||
} | ||
|
||
if props := resp.VirtualWanProperties; props != nil { | ||
d.Set("disable_vpn_encryption", props.DisableVpnEncryption) | ||
d.Set("security_provider_name", props.SecurityProviderName) | ||
d.Set("allow_branch_to_branch_traffic", props.AllowBranchToBranchTraffic) | ||
d.Set("allow_vnet_to_vnet_traffic", props.AllowVnetToVnetTraffic) | ||
d.Set("office365_local_breakout_category", props.Office365LocalBreakoutCategory) | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmVirtualWanDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).network.VirtualWanClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
name := id.Path["virtualWans"] | ||
|
||
future, err := client.Delete(ctx, resourceGroup, name) | ||
if err != nil { | ||
// deleted outside of Terraform | ||
if response.WasNotFound(future.Response()) { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error deleting Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
if !response.WasNotFound(future.Response()) { | ||
return fmt.Errorf("Error waiting for the deletion of Virtual WAN %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.