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

New Resource & Data Source: azurerm_app_service_virtual_network_connection_gateway #4458

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
"root_certificate": {
Type: schema.TypeSet,
Optional: true,

Computed: true,
ConflictsWith: []string{
"vpn_client_configuration.0.radius_server_address",
"vpn_client_configuration.0.radius_server_secret",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package web

import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmAppServiceVirtualNetworkConnectionGateway() *schema.Resource {
return &schema.Resource{
Read: dataSourceAppServiceVirtualNetworkConnectionGatewayRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"app_service_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateAppServiceName,
},

"resource_group_name": azure.SchemaResourceGroupName(),

"virtual_network_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"certificate_blob": {
Type: schema.TypeString,
Computed: true,
},

"certificate_thumbprint": {
Type: schema.TypeString,
Computed: true,
},

"dns_servers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"name": {
Type: schema.TypeString,
Computed: true,
},

"resync_required": {
Type: schema.TypeBool,
Computed: true,
},

"virtual_network_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceAppServiceVirtualNetworkConnectionGatewayRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Web.AppServicesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

resGroup := d.Get("resource_group_name").(string)
appServiceName := d.Get("app_service_name").(string)
vnetName := d.Get("virtual_network_name").(string)

resp, err := client.GetVnetConnection(ctx, resGroup, appServiceName, vnetName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[DEBUG] App Service Virtual Network Connection for app %q vnet %q was not found in Resource Group %q - removnig from state!", appServiceName, vnetName, resGroup)
return nil
}

return fmt.Errorf("Error making Read request on App Service Virtual Network Connection for app %q vnet %q (Resource Group %q): %+v", appServiceName, vnetName, resGroup, err)
}

if resp.ID != nil || *resp.ID != "" {
d.SetId(*resp.ID)
}
d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("app_service_name", appServiceName)
if props := resp.VnetInfoProperties; props != nil {
d.Set("virtual_network_id", props.VnetResourceID)
d.Set("certificate_thumbprint", props.CertThumbprint)
d.Set("certificate_blob", props.CertBlob)
d.Set("resync_required", props.ResyncRequired)
if props.DNSServers != nil {
d.Set("dns_servers", strings.Split(*props.DNSServers, ","))
} else {
d.Set("dns_servers", []string{})
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type AppServiceVirtualNetworkConnectionId struct {
ResourceGroup string
AppServiceName string
Name string
}

func AppServiceVirtualNetworkConnectionID(input string) (*AppServiceVirtualNetworkConnectionId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse App Service Environment ID %q: %+v", input, err)
}

appServiceVirtualNetworkConnection := AppServiceVirtualNetworkConnectionId{
ResourceGroup: id.ResourceGroup,
}

if appServiceVirtualNetworkConnection.AppServiceName, err = id.PopSegment("sites"); err != nil {
return nil, err
}

if appServiceVirtualNetworkConnection.Name, err = id.PopSegment("virtualNetworkConnections"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &appServiceVirtualNetworkConnection, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package parse

import "testing"

func TestParseAppServiceVirtualNetworkConnectionID(t *testing.T) {
testData := []struct {
Name string
Input string
Error bool
Expect *AppServiceVirtualNetworkConnectionId
}{
{
Name: "Empty",
Input: "",
Error: true,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Error: true,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Error: true,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Error: true,
},
{
Name: "Missing App Service Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/providers/Microsoft.Web/sites/",
Error: true,
},
{
Name: "Missing Virtual Network Connection Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/providers/Microsoft.Web/sites/as1/virtualNetworkConnections/",
Error: true,
},
{
Name: "Valid",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Web/sites/as1/virtualNetworkConnections/vnet1",
Error: false,
Expect: &AppServiceVirtualNetworkConnectionId{
ResourceGroup: "resGroup1",
AppServiceName: "as1",
Name: "vnet1",
},
},
{
Name: "Wrong Case",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Web/sites/as1/virtualnetworkconnections/vnet1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := AppServiceVirtualNetworkConnectionID(v.Input)
if err != nil {
if v.Expect == nil {
continue
}
t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.Name != v.Expect.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name)
}

if actual.ResourceGroup != v.Expect.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup)
}
}
}
36 changes: 19 additions & 17 deletions azurerm/internal/services/web/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ func (r Registration) WebsiteCategories() []string {
// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_app_service": dataSourceArmAppService(),
"azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(),
"azurerm_app_service_environment": dataSourceArmAppServiceEnvironment(),
"azurerm_app_service_certificate": dataSourceAppServiceCertificate(),
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_function_app": dataSourceArmFunctionApp(),
"azurerm_app_service": dataSourceArmAppService(),
"azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(),
"azurerm_app_service_environment": dataSourceArmAppServiceEnvironment(),
"azurerm_app_service_certificate": dataSourceAppServiceCertificate(),
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_function_app": dataSourceArmFunctionApp(),
"azurerm_app_service_virtual_network_connection_gateway": dataSourceArmAppServiceVirtualNetworkConnectionGateway(),
}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(),
"azurerm_app_service_certificate": resourceArmAppServiceCertificate(),
"azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(),
"azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(),
"azurerm_app_service_environment": resourceArmAppServiceEnvironment(),
"azurerm_app_service_plan": resourceArmAppServicePlan(),
"azurerm_app_service_slot": resourceArmAppServiceSlot(),
"azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(),
"azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(),
"azurerm_app_service": resourceArmAppService(),
"azurerm_function_app": resourceArmFunctionApp(),
"azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(),
"azurerm_app_service_certificate": resourceArmAppServiceCertificate(),
"azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(),
"azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(),
"azurerm_app_service_environment": resourceArmAppServiceEnvironment(),
"azurerm_app_service_plan": resourceArmAppServicePlan(),
"azurerm_app_service_slot": resourceArmAppServiceSlot(),
"azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(),
"azurerm_app_service_virtual_network_connection_gateway": resourceArmAppServiceVirtualNetworkConnectionGateway(),
"azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(),
"azurerm_app_service": resourceArmAppService(),
"azurerm_function_app": resourceArmFunctionApp(),
}
}
Loading