From 1f466064d362b7dd6de54b81678e54e3ec43769d Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:29:36 +0800 Subject: [PATCH] update per comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> --- ... => application_load_balancer_frontend.go} | 37 +++++------ ...pplication_load_balancer_frontend_test.go} | 3 - ... => application_load_balancer_resource.go} | 0 ...pplication_load_balancer_resource_test.go} | 0 ...tion_load_balancer_frontend.html.markdown} | 0 ...ng_application_load_balancer.html.markdown | 62 ------------------- 6 files changed, 19 insertions(+), 83 deletions(-) rename internal/services/servicenetworking/{service_networking_application_load_balancer_frontend_resource.go => application_load_balancer_frontend.go} (87%) rename internal/services/servicenetworking/{service_networking_application_load_balancer_frontend_resource_test.go => application_load_balancer_frontend_test.go} (95%) rename internal/services/servicenetworking/{service_networking_application_load_balancer_resource.go => application_load_balancer_resource.go} (100%) rename internal/services/servicenetworking/{service_networking_application_load_balancer_resource_test.go => application_load_balancer_resource_test.go} (100%) rename website/docs/r/{service_networking_application_load_balancer_frontend.html.markdown => application_load_balancer_frontend.html.markdown} (100%) delete mode 100644 website/docs/r/service_networking_application_load_balancer.html.markdown diff --git a/internal/services/servicenetworking/service_networking_application_load_balancer_frontend_resource.go b/internal/services/servicenetworking/application_load_balancer_frontend.go similarity index 87% rename from internal/services/servicenetworking/service_networking_application_load_balancer_frontend_resource.go rename to internal/services/servicenetworking/application_load_balancer_frontend.go index 664b4ab08a78..ce7377add3c4 100644 --- a/internal/services/servicenetworking/service_networking_application_load_balancer_frontend_resource.go +++ b/internal/services/servicenetworking/application_load_balancer_frontend.go @@ -8,9 +8,9 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-05-01-preview/frontendsinterface" + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-05-01-preview/trafficcontrollerinterface" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" @@ -23,7 +23,6 @@ type FrontendsResource struct{} type FrontendsModel struct { Name string `tfschema:"name"` ApplicationLoadBalancerId string `tfschema:"application_load_balancer_id"` - Location string `tfschema:"location"` Fqdn string `tfschema:"fully_qualified_domain_name"` Tags map[string]interface{} `tfschema:"tags"` } @@ -46,8 +45,6 @@ func (f FrontendsResource) Arguments() map[string]*schema.Schema { ValidateFunc: frontendsinterface.ValidateTrafficControllerID, }, - "location": commonschema.Location(), - "tags": commonschema.Tags(), } } @@ -77,6 +74,7 @@ func (f FrontendsResource) Create() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + trafficControllerClient := metadata.Client.ServiceNetworking.TrafficControllerInterface client := metadata.Client.ServiceNetworking.FrontendsInterface var config FrontendsModel @@ -89,6 +87,19 @@ func (f FrontendsResource) Create() sdk.ResourceFunc { return err } + controllerId := trafficcontrollerinterface.NewTrafficControllerID(trafficControllerId.SubscriptionId, trafficControllerId.ResourceGroupName, trafficControllerId.TrafficControllerName) + + controller, err := trafficControllerClient.Get(ctx, controllerId) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", controllerId, err) + } + + if controller.Model == nil { + return fmt.Errorf("retrieving %s: Model was nil", controllerId) + } + + loc := controller.Model.Location + id := frontendsinterface.NewFrontendID(trafficControllerId.SubscriptionId, trafficControllerId.ResourceGroupName, trafficControllerId.TrafficControllerName, config.Name) resp, err := client.Get(ctx, id) @@ -103,7 +114,7 @@ func (f FrontendsResource) Create() sdk.ResourceFunc { } frontend := frontendsinterface.Frontend{ - Location: location.Normalize(config.Location), + Location: loc, Properties: &frontendsinterface.FrontendProperties{}, Tags: tags.Expand(config.Tags), } @@ -145,7 +156,6 @@ func (f FrontendsResource) Read() sdk.ResourceFunc { } if model := resp.Model; model != nil { - state.Location = location.NormalizeNilable(pointer.To(model.Location)) state.Tags = tags.Flatten(model.Tags) if prop := model.Properties; prop != nil { @@ -174,22 +184,13 @@ func (f FrontendsResource) Update() sdk.ResourceFunc { return fmt.Errorf("decoding %v", err) } - resp, err := client.Get(ctx, *id) - if err != nil { - return fmt.Errorf("retiring %s: %+v", *id, err) - } - - if resp.Model == nil { - return fmt.Errorf("retiring %s: Model was nil", *id) - } - - model := *resp.Model + update := frontendsinterface.FrontendUpdate{} if metadata.ResourceData.HasChange("tags") { - model.Tags = tags.Expand(config.Tags) + update.Tags = tags.Expand(config.Tags) } - if err := client.CreateOrUpdateThenPoll(ctx, *id, model); err != nil { + if _, err := client.Update(ctx, *id, update); err != nil { return fmt.Errorf("updating `azurerm_alb_frontend` %s: %+v", *id, err) } diff --git a/internal/services/servicenetworking/service_networking_application_load_balancer_frontend_resource_test.go b/internal/services/servicenetworking/application_load_balancer_frontend_test.go similarity index 95% rename from internal/services/servicenetworking/service_networking_application_load_balancer_frontend_resource_test.go rename to internal/services/servicenetworking/application_load_balancer_frontend_test.go index 4fa98be27879..21520100dc2e 100644 --- a/internal/services/servicenetworking/service_networking_application_load_balancer_frontend_resource_test.go +++ b/internal/services/servicenetworking/application_load_balancer_frontend_test.go @@ -130,7 +130,6 @@ provider "azurerm" { resource "azurerm_application_load_balancer_frontend" "test" { name = "acct-frnt-%d" application_load_balancer_id = azurerm_application_load_balancer.test.id - location = azurerm_application_load_balancer.test.location } `, r.template(data), data.RandomInteger) } @@ -147,7 +146,6 @@ provider "azurerm" { resource "azurerm_application_load_balancer_frontend" "test" { name = "acct-frnt-%d" application_load_balancer_id = azurerm_application_load_balancer.test.id - location = azurerm_application_load_balancer.test.location tags = { "tag1" = "value1" } @@ -162,7 +160,6 @@ func (r ApplicationLoadBalancerFrontendResource) requiresImport(data acceptance. resource "azurerm_application_load_balancer_frontend" "import" { name = azurerm_application_load_balancer_frontend.test.name application_load_balancer_id = azurerm_application_load_balancer_frontend.test.application_load_balancer_id - location = azurerm_application_load_balancer_frontend.test.location } `, r.basic(data)) diff --git a/internal/services/servicenetworking/service_networking_application_load_balancer_resource.go b/internal/services/servicenetworking/application_load_balancer_resource.go similarity index 100% rename from internal/services/servicenetworking/service_networking_application_load_balancer_resource.go rename to internal/services/servicenetworking/application_load_balancer_resource.go diff --git a/internal/services/servicenetworking/service_networking_application_load_balancer_resource_test.go b/internal/services/servicenetworking/application_load_balancer_resource_test.go similarity index 100% rename from internal/services/servicenetworking/service_networking_application_load_balancer_resource_test.go rename to internal/services/servicenetworking/application_load_balancer_resource_test.go diff --git a/website/docs/r/service_networking_application_load_balancer_frontend.html.markdown b/website/docs/r/application_load_balancer_frontend.html.markdown similarity index 100% rename from website/docs/r/service_networking_application_load_balancer_frontend.html.markdown rename to website/docs/r/application_load_balancer_frontend.html.markdown diff --git a/website/docs/r/service_networking_application_load_balancer.html.markdown b/website/docs/r/service_networking_application_load_balancer.html.markdown deleted file mode 100644 index eaa4e35e5189..000000000000 --- a/website/docs/r/service_networking_application_load_balancer.html.markdown +++ /dev/null @@ -1,62 +0,0 @@ ---- -subcategory: "Service Networking" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_application_load_balancer" -description: |- - Manages an Application Gateway for Containers (ALB). ---- - -# azurerm_application_load_balancer - -Manages an Application Gateway for Containers (ALB). - -## Example Usage - -```hcl -resource "azurerm_application_load_balancer" "example" { - name = "example" - resource_group_name = "example" - location = "West Europe" -} -``` - -## Arguments Reference - -The following arguments are supported: - -* `name` - (Required) The name which should be used for this resource. Changing this forces a new resource to be created. - -* `resource_group_name` - (Required) The name of the Resource Group where the resource should exist. Changing this forces a new resource to be created. - -* `location` - (Required) The Azure Region where the resource should exist. Changing this forces a new resource to be created. Available regions can be found [here](https://learn.microsoft.com/en-us/azure/application-gateway/for-containers/overview#supported-regions) - -**Note:** The available values of `location` are `northeurope` and `north central us`. - ---- - -* `tags` - (Optional) A mapping of tags which should be assigned to the Application Gateway for Containers. - -## Attributes Reference - -In addition to the Arguments listed above - the following Attributes are exported: - -* `id` - The ID of the resource. - -* `configuration_endpoint` - The list of configuration endpoints for the resource. - -## Timeouts - -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: - -* `create` - (Defaults to 30 minutes) Used when creating the Application Gateway for Containers resource -* `read` - (Defaults to 5 minutes) Used when retrieving the Application Gateway for Containers resource. -* `update` - (Defaults to 30 minutes) Used when updating the Application Gateway for Containers resource -* `delete` - (Defaults to 30 minutes) Used when deleting the Application Gateway for Containers resource. - -## Import - -Application Gateway for Containers (ALB) can be imported using the `resource id`, e.g. - -```shell -terraform import azurerm_application_load_balancer.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ServiceNetworking/trafficControllers/alb1 -```