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

App Service: Virtual Network Integration #1896

Merged
merged 2 commits into from
Sep 9, 2018
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
18 changes: 15 additions & 3 deletions azurerm/helpers/azure/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func SchemaAppServiceSiteConfig() *schema.Schema {
string(web.OneFullStopTwo),
}, false),
},

"virtual_network_name": {
Type: schema.TypeString,
Optional: true,
},
},
},
}
Expand Down Expand Up @@ -321,6 +326,10 @@ func ExpandAppServiceSiteConfig(input interface{}) web.SiteConfig {
siteConfig.MinTLSVersion = web.SupportedTLSVersions(v.(string))
}

if v, ok := config["virtual_network_name"]; ok {
siteConfig.VnetName = utils.String(v.(string))
}

return siteConfig
}

Expand All @@ -337,14 +346,13 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
result["always_on"] = *input.AlwaysOn
}

documents := make([]string, 0)
if input.DefaultDocuments != nil {
documents := make([]string, 0)
for _, document := range *input.DefaultDocuments {
documents = append(documents, document)
}

result["default_documents"] = documents
}
result["default_documents"] = documents

if input.NetFrameworkVersion != nil {
result["dotnet_framework_version"] = *input.NetFrameworkVersion
Expand Down Expand Up @@ -423,6 +431,10 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
result["linux_fx_version"] = *input.LinuxFxVersion
}

if input.VnetName != nil {
result["virtual_network_name"] = *input.VnetName
}

result["scm_type"] = string(input.ScmType)
result["ftps_state"] = string(input.FtpsState)
result["min_tls_version"] = string(input.MinTLSVersion)
Expand Down
142 changes: 142 additions & 0 deletions azurerm/resource_arm_app_service_slot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,34 @@ func TestAccAzureRMAppServiceSlot_remoteDebugging(t *testing.T) {
})
}

func TestAccAzureRMAppServiceSlot_virtualNetwork(t *testing.T) {
resourceName := "azurerm_app_service_slot.test"
ri := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMAppServiceSlot_virtualNetwork(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn-%d", ri)),
),
},
{
Config: testAccAzureRMAppServiceSlot_virtualNetworkUpdated(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn2-%d", ri)),
),
},
},
})
}

func TestAccAzureRMAppServiceSlot_windowsDotNet2(t *testing.T) {
resourceName := "azurerm_app_service_slot.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -1475,6 +1503,120 @@ resource "azurerm_app_service_slot" "test" {
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMAppServiceSlot_virtualNetwork(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

subnet {
name = "internal"
address_prefix = "10.0.1.0/24"
}
}

resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
}

resource "azurerm_app_service_slot" "test" {
name = "acctestASSlot-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
app_service_name = "${azurerm_app_service.test.name}"

site_config {
virtual_network_name = "${azurerm_virtual_network.test.name}"
}
}
`, rInt, location, rInt, rInt, rInt, rInt)
}

func testAccAzureRMAppServiceSlot_virtualNetworkUpdated(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

subnet {
name = "internal"
address_prefix = "10.0.1.0/24"
}
}

resource "azurerm_virtual_network" "second" {
name = "acctestvn2-%d"
address_space = ["172.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

subnet {
name = "internal"
address_prefix = "172.0.1.0/24"
}
}

resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
}

resource "azurerm_app_service_slot" "test" {
name = "acctestASSlot-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
app_service_name = "${azurerm_app_service.test.name}"

site_config {
virtual_network_name = "${azurerm_virtual_network.second.name}"
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMAppServiceSlot_windowsDotNet(rInt int, location, version string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
126 changes: 126 additions & 0 deletions azurerm/resource_arm_app_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,34 @@ func TestAccAzureRMAppService_clientAffinityDisabled(t *testing.T) {
})
}

func TestAccAzureRMAppService_virtualNetwork(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMAppService_virtualNetwork(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn-%d", ri)),
),
},
{
Config: testAccAzureRMAppService_virtualNetworkUpdated(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn2-%d", ri)),
),
},
},
})
}

func TestAccAzureRMAppService_enableManageServiceIdentity(t *testing.T) {

resourceName := "azurerm_app_service.test"
Expand Down Expand Up @@ -1212,6 +1240,104 @@ resource "azurerm_app_service" "test" {
`, rInt, location, rInt, rInt, clientAffinity)
}

func testAccAzureRMAppService_virtualNetwork(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

subnet {
name = "internal"
address_prefix = "10.0.1.0/24"
}
}

resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
virtual_network_name = "${azurerm_virtual_network.test.name}"
}
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMAppService_virtualNetworkUpdated(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

subnet {
name = "internal"
address_prefix = "10.0.1.0/24"
}
}

resource "azurerm_virtual_network" "second" {
name = "acctestvn2-%d"
address_space = ["172.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

subnet {
name = "internal"
address_prefix = "172.0.1.0/24"
}
}

resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
virtual_network_name = "${azurerm_virtual_network.second.name}"
}
}
`, rInt, location, rInt, rInt, rInt, rInt)
}

func testAccAzureRMAppService_mangedServiceIdentity(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
8 changes: 5 additions & 3 deletions website/docs/d/app_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ output "app_service_id" {

* `http2_enabled` - Is HTTP2 Enabled on this App Service?

* `ftps_state` - State of FTP / FTPS service for this AppService.

* `ip_restriction` - One or more `ip_restriction` blocks as defined below.

* `java_version` - The version of Java in use.
Expand All @@ -81,6 +83,8 @@ output "app_service_id" {

* `java_container_version` - The version of the Java Container in use.

* `linux_fx_version` - Linux App Framework and version for the AppService.

* `local_mysql_enabled` - Is "MySQL In App" Enabled? This runs a local MySQL instance with your app and shares resources from the App Service plan.

* `managed_pipeline_mode` - The Managed Pipeline Mode used in this App Service.
Expand All @@ -101,9 +105,7 @@ output "app_service_id" {

* `websockets_enabled` - Are WebSockets enabled for this App Service?

* `ftps_state` - State of FTP / FTPS service for this AppService.

* `linux_fx_version` - Linux App Framework and version for the AppService.
* `virtual_network_name` - The name of the Virtual Network which this App Service is attached to.

---

Expand Down
Loading