Skip to content

Commit

Permalink
update per comments
Browse files Browse the repository at this point in the history
Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
  • Loading branch information
ziyeqf committed Oct 12, 2023
1 parent e9eb2b5 commit 1f46606
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
}
Expand All @@ -46,8 +45,6 @@ func (f FrontendsResource) Arguments() map[string]*schema.Schema {
ValidateFunc: frontendsinterface.ValidateTrafficControllerID,
},

"location": commonschema.Location(),

"tags": commonschema.Tags(),
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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),
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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"
}
Expand All @@ -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))
Expand Down

This file was deleted.

0 comments on commit 1f46606

Please sign in to comment.