-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_app_service_environment_v3
(#11174)
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
1 parent
80b4515
commit 13c64c6
Showing
9 changed files
with
945 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
111 changes: 111 additions & 0 deletions
111
azurerm/internal/services/web/app_service_environment_v3_data_source.go
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,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) | ||
}, | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
azurerm/internal/services/web/app_service_environment_v3_data_source_test.go
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,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)) | ||
} |
Oops, something went wrong.