Skip to content

Commit

Permalink
New Resource: azurerm_app_service_environment_v3 (#11174)
Browse files Browse the repository at this point in the history
Co-authored-by: kt <[email protected]>

This PR introduces the preview resource, App Service Environment V3.

SDK/API coverage is incomplete, so two notable items are missing, but will be added if/when they are supported. (These are Host group deployment, and upgrade preference.)

supersedes #10304
Resolves #9420
  • Loading branch information
jackofallops authored May 4, 2021
1 parent 80b4515 commit 13c64c6
Show file tree
Hide file tree
Showing 9 changed files with 945 additions and 0 deletions.
1 change: 1 addition & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
eventhub.Registration{},
loadbalancer.Registration{},
resource.Registration{},
web.Registration{},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package web

import (
"context"
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/sdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

type AppServiceEnvironmentV3DataSource struct{}

var _ sdk.DataSource = AppServiceEnvironmentV3DataSource{}

func (r AppServiceEnvironmentV3DataSource) Arguments() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.AppServiceEnvironmentName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
}
}

func (r AppServiceEnvironmentV3DataSource) Attributes() map[string]*schema.Schema {
return map[string]*schema.Schema{
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},

"cluster_setting": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},

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

"tags": tags.SchemaDataSource(),
}
}

func (r AppServiceEnvironmentV3DataSource) ModelObject() interface{} {
return AppServiceEnvironmentV3Model{}
}

func (r AppServiceEnvironmentV3DataSource) ResourceType() string {
return "azurerm_app_service_environment_v3"
}

func (r AppServiceEnvironmentV3DataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,

Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Web.AppServiceEnvironmentsClient
id, err := parse.AppServiceEnvironmentID(metadata.ResourceData.Id())
if err != nil {
return err
}

existing, err := client.Get(ctx, id.ResourceGroup, id.HostingEnvironmentName)
if err != nil {
if utils.ResponseWasNotFound(existing.Response) {
return metadata.MarkAsGone(id)
}
return fmt.Errorf("retrieving %s: %+v", id, err)
}

model := AppServiceEnvironmentV3Model{
Name: id.HostingEnvironmentName,
ResourceGroup: id.ResourceGroup,
Location: location.NormalizeNilable(existing.Location),
}

if props := existing.AppServiceEnvironment; props != nil {
if props.VirtualNetwork != nil {
model.SubnetId = utils.NormalizeNilableString(props.VirtualNetwork.ID)
}

model.PricingTier = utils.NormalizeNilableString(props.MultiSize)

model.ClusterSetting = flattenClusterSettingsModel(props.ClusterSettings)
}

model.Tags = tags.Flatten(existing.Tags)

return metadata.Encode(&model)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package web_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
)

type AppServiceEnvironmentV3DataSource struct{}

func TestAccAppServiceEnvironmentV3DataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_app_service_environment_v3", "test")

data.DataSourceTest(t, []resource.TestStep{
{
Config: AppServiceEnvironmentV3DataSource{}.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("cluster_setting.#").HasValue("2"),
check.That(data.ResourceName).Key("tags.#").HasValue("2"),
),
},
})
}

func (AppServiceEnvironmentV3DataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_app_service_environment_v3" "test" {
name = azurerm_app_service_environment_v3.test.name
resource_group_name = azurerm_app_service_environment_v3.test.resource_group_name
}
`, AppServiceEnvironmentV3Resource{}.complete(data))
}
Loading

0 comments on commit 13c64c6

Please sign in to comment.