Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Jan 31, 2024
1 parent c2372a1 commit 5998079
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions internal/services/appservice/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ func NewClient(o *common.ClientOptions) (*Client, error) {

webAppServiceClient, err := webapps.NewWebAppsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Api client: %+v", err)
return nil, fmt.Errorf("building WebApps client: %+v", err)
}
o.Configure(webAppServiceClient.Client, o.Authorizers.ResourceManager)

resourceProvidersClient, err := resourceproviders.NewResourceProvidersClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Api client: %+v", err)
return nil, fmt.Errorf("building ResourceProviders client: %+v", err)
}
o.Configure(resourceProvidersClient.Client, o.Authorizers.ResourceManager)

servicePlanClient, err := appserviceplans.NewAppServicePlansClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Api client: %+v", err)
return nil, fmt.Errorf("building ServicePlan client: %+v", err)
}
o.Configure(servicePlanClient.Client, o.Authorizers.ResourceManager)

Expand Down
21 changes: 2 additions & 19 deletions internal/services/appservice/function_app_active_slot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package appservice
import (
"context"
"fmt"
"regexp"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/custompollers"

Check failure on line 9 in internal/services/appservice/function_app_active_slot_resource.go

View workflow job for this annotation

GitHub Actions / golint

File is not `goimports`-ed (goimports)
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand All @@ -15,7 +15,6 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-01-01/webapps"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/resourceproviders/custompollers"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)
Expand Down Expand Up @@ -104,24 +103,8 @@ func (r FunctionAppActiveSlotResource) Create() sdk.ResourceFunc {
locks.ByID(appId.ID())
defer locks.UnlockByID(appId.ID())

if resp, err := client.SwapSlotWithProduction(ctx, appId, csmSlotEntity); err != nil {
if _, err := client.SwapSlotWithProduction(ctx, appId, csmSlotEntity); err != nil {
return fmt.Errorf("making %s the active slot: %+v", id.SlotName, err)
} else {
err = resp.Poller.PollUntilDone(ctx)
if err != nil {
// This is a workaround for a bug in the Azure API where the LRO Success doesn't provide a status or provisioningState in the response
if regexp.MustCompile("expected either `provisioningState` or `status` to be returned from the LRO API but both were empty").Match([]byte(err.Error())) {
if checkSwap, appErr := client.Get(ctx, appId); appErr != nil {
if checkSwap.Model != nil && checkSwap.Model.Properties != nil && checkSwap.Model.Properties.SlotSwapStatus != nil {
swapStatus := pointer.From(checkSwap.Model.Properties.SlotSwapStatus)
if pointer.From(swapStatus.SourceSlotName) != id.SlotName {
return err
}
}
return err
}
}
}
}

pollerType := custompollers.NewAppServiceActiveSlotPoller(client, appId, *id)
Expand Down
26 changes: 10 additions & 16 deletions internal/services/appservice/function_app_function_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type FunctionAppFunctionResource struct{}
Expand Down Expand Up @@ -224,9 +223,9 @@ func (r FunctionAppFunctionResource) Create() sdk.ResourceFunc {
fnEnvelope := webapps.FunctionEnvelope{
Properties: &webapps.FunctionEnvelopeProperties{
Config: pointer.To(confJSON),
TestData: utils.String(appFunction.TestData),
Language: utils.String(appFunction.Language),
IsDisabled: utils.Bool(!appFunction.Enabled),
TestData: pointer.To(appFunction.TestData),
Language: pointer.To(appFunction.Language),
IsDisabled: pointer.To(!appFunction.Enabled),
Files: expandFunctionFiles(appFunction.Files),
},
}
Expand Down Expand Up @@ -262,12 +261,8 @@ func (r FunctionAppFunctionResource) Create() sdk.ResourceFunc {
locks.ByID(appId.ID())
defer locks.UnlockByID(appId.ID())

if result, err := client.CreateFunction(ctx, id, fnEnvelope); err != nil {
if err := client.CreateFunctionThenPoll(ctx, id, fnEnvelope); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
} else {
if err = result.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("waiting for creation of %s: %+v", id, err)
}
}

metadata.SetID(id)
Expand Down Expand Up @@ -296,13 +291,12 @@ func (r FunctionAppFunctionResource) Read() sdk.ResourceFunc {
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

appFunc := FunctionAppFunctionModel{}
appFunc := FunctionAppFunctionModel{
Name: id.FunctionName,
AppID: commonids.NewAppServiceID(id.SubscriptionId, id.ResourceGroupName, id.SiteName).ID(),
}

if model := existing.Model; model != nil {
appFunc = FunctionAppFunctionModel{
Name: id.FunctionName,
AppID: commonids.NewAppServiceID(id.SubscriptionId, id.ResourceGroupName, id.SiteName).ID(),
}
if props := model.Properties; props != nil {
appFunc.ConfigURL = pointer.From(props.ConfigHref)
appFunc.Enabled = !pointer.From(props.IsDisabled)
Expand Down Expand Up @@ -430,11 +424,11 @@ func (r FunctionAppFunctionResource) Update() sdk.ResourceFunc {
}

if metadata.ResourceData.HasChange("enabled") {
model.Properties.IsDisabled = utils.Bool(!appFunction.Enabled)
model.Properties.IsDisabled = pointer.To(!appFunction.Enabled)
}

if metadata.ResourceData.HasChange("test_data") {
model.Properties.TestData = utils.String(appFunction.TestData)
model.Properties.TestData = pointer.To(appFunction.TestData)
}

deadline, ok := ctx.Deadline()
Expand Down
5 changes: 4 additions & 1 deletion internal/services/appservice/linux_web_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ func (r LinuxWebAppDataSource) Read() sdk.ResourceFunc {
}

baseID := commonids.NewAppServiceID(subscriptionId, webApp.ResourceGroup, webApp.Name)
id, _ := commonids.ParseWebAppID(baseID.ID())
id, err := commonids.ParseWebAppID(baseID.ID())
if err != nil {
return err
}

existing, err := client.Get(ctx, *id)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion internal/services/appservice/web_app_active_slot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package appservice
import (
"context"
"fmt"

Check failure on line 8 in internal/services/appservice/web_app_active_slot_resource.go

View workflow job for this annotation

GitHub Actions / golint

File is not `goimports`-ed (goimports)
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/custompollers"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand Down Expand Up @@ -101,10 +103,16 @@ func (r WebAppActiveSlotResource) Create() sdk.ResourceFunc {
locks.ByID(appId.ID())
defer locks.UnlockByID(appId.ID())

if err := client.SwapSlotWithProductionThenPoll(ctx, appId, csmSlotEntity); err != nil {
if _, err := client.SwapSlotWithProduction(ctx, appId, csmSlotEntity); err != nil {
return fmt.Errorf("making %s the active slot: %+v", id.SlotName, err)
}

pollerType := custompollers.NewAppServiceActiveSlotPoller(client, appId, *id)
poller := pollers.NewPoller(pollerType, 10*time.Second, pollers.DefaultNumberOfDroppedConnectionsToAllow)
if err := poller.PollUntilDone(ctx); err != nil {
return err
}

metadata.SetID(appId)

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func (r WebAppHybridConnectionResource) Create() sdk.ResourceFunc {
return fmt.Errorf("checking for presence of existing %s: %s", id, err)
}
}
if existing.Model != nil && existing.Model.Id != nil && *existing.Model.Id != "" {
return tf.ImportAsExistsError(r.ResourceType(), *existing.Model.Id)
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError(r.ResourceType(), id.ID())
}

envelope := webapps.HybridConnection{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ func (d WindowsFunctionAppDataSource) Read() sdk.ResourceFunc {
}

baseID := commonids.NewAppServiceID(subscriptionId, functionApp.ResourceGroup, functionApp.Name)
id, _ := commonids.ParseFunctionAppID(baseID.ID())
id, err := commonids.ParseFunctionAppID(baseID.ID())
if err != nil {
return err
}

existing, err := client.Get(ctx, *id)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ func (r WindowsFunctionAppResource) Create() sdk.ResourceFunc {
subscriptionId := metadata.Client.Account.SubscriptionId

baseId := commonids.NewAppServiceID(subscriptionId, functionApp.ResourceGroup, functionApp.Name)
id, _ := commonids.ParseFunctionAppID(baseId.ID())
id, err := commonids.ParseFunctionAppID(baseId.ID())
if err != nil {
return err
}

servicePlanId, err := commonids.ParseAppServicePlanID(functionApp.ServicePlanId)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/services/appservice/windows_web_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ func (d WindowsWebAppDataSource) Read() sdk.ResourceFunc {
}

baseId := commonids.NewAppServiceID(subscriptionId, webApp.ResourceGroup, webApp.Name)
id, _ := commonids.ParseWebAppID(baseId.ID())
id, err := commonids.ParseWebAppID(baseId.ID())
if err != nil {
return err
}

existing, err := client.Get(ctx, *id)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/services/appservice/windows_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ func (r WindowsWebAppResource) Create() sdk.ResourceFunc {
subscriptionId := metadata.Client.Account.SubscriptionId

baseId := commonids.NewAppServiceID(subscriptionId, webApp.ResourceGroup, webApp.Name)
id, _ := commonids.ParseWebAppID(baseId.ID())
id, err := commonids.ParseWebAppID(baseId.ID())
if err != nil {
return err
}

existing, err := client.Get(ctx, *id)
if err != nil && !response.WasNotFound(existing.HttpResponse) {
Expand Down

0 comments on commit 5998079

Please sign in to comment.