@@ -17,6 +17,7 @@ import (
1717 "github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
1818 "github.com/hashicorp/go-azure-helpers/resourcemanager/location"
1919 "github.com/hashicorp/go-azure-sdk/resource-manager/web/2023-12-01/webapps"
20+ "github.com/hashicorp/terraform-provider-azurerm/internal/features"
2021 "github.com/hashicorp/terraform-provider-azurerm/internal/locks"
2122 "github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
2223 "github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers"
@@ -64,12 +65,15 @@ type WindowsWebAppSlotModel struct {
6465 ZipDeployFile string `tfschema:"zip_deploy_file"`
6566 Tags map [string ]string `tfschema:"tags"`
6667 VirtualNetworkBackupRestoreEnabled bool `tfschema:"virtual_network_backup_restore_enabled"`
68+ VirtualNetworkImagePullEnabled bool `tfschema:"virtual_network_image_pull_enabled"`
6769 VirtualNetworkSubnetID string `tfschema:"virtual_network_subnet_id"`
6870}
6971
70- var _ sdk.ResourceWithUpdate = WindowsWebAppSlotResource {}
71-
72- var _ sdk.ResourceWithStateMigration = WindowsWebAppSlotResource {}
72+ var (
73+ _ sdk.ResourceWithCustomizeDiff = WindowsWebAppSlotResource {}
74+ _ sdk.ResourceWithUpdate = WindowsWebAppSlotResource {}
75+ _ sdk.ResourceWithStateMigration = WindowsWebAppSlotResource {}
76+ )
7377
7478func (r WindowsWebAppSlotResource ) ModelObject () interface {} {
7579 return & WindowsWebAppSlotModel {}
@@ -84,7 +88,7 @@ func (r WindowsWebAppSlotResource) IDValidationFunc() pluginsdk.SchemaValidateFu
8488}
8589
8690func (r WindowsWebAppSlotResource ) Arguments () map [string ]* pluginsdk.Schema {
87- return map [string ]* pluginsdk.Schema {
91+ s := map [string ]* pluginsdk.Schema {
8892 "name" : {
8993 Type : pluginsdk .TypeString ,
9094 Required : true ,
@@ -210,12 +214,28 @@ func (r WindowsWebAppSlotResource) Arguments() map[string]*pluginsdk.Schema {
210214 Default : false ,
211215 },
212216
217+ "virtual_network_image_pull_enabled" : {
218+ Type : pluginsdk .TypeBool ,
219+ Optional : true ,
220+ Default : false ,
221+ },
222+
213223 "virtual_network_subnet_id" : {
214224 Type : pluginsdk .TypeString ,
215225 Optional : true ,
216226 ValidateFunc : commonids .ValidateSubnetID ,
217227 },
218228 }
229+
230+ if ! features .FivePointOh () {
231+ s ["virtual_network_image_pull_enabled" ] = & pluginsdk.Schema {
232+ Type : pluginsdk .TypeBool ,
233+ Optional : true ,
234+ Computed : true ,
235+ }
236+ }
237+
238+ return s
219239}
220240
221241func (r WindowsWebAppSlotResource ) Attributes () map [string ]* pluginsdk.Schema {
@@ -360,6 +380,19 @@ func (r WindowsWebAppSlotResource) Create() sdk.ResourceFunc {
360380 },
361381 }
362382
383+ if ! features .FivePointOh () {
384+ rawVnetImagePullEnabled , err := metadata .GetRawConfigAt ("virtual_network_image_pull_enabled" )
385+ if err != nil {
386+ return err
387+ }
388+
389+ if ! rawVnetImagePullEnabled .IsNull () {
390+ siteEnvelope .Properties .VnetImagePullEnabled = pointer .To (webAppSlot .VirtualNetworkImagePullEnabled )
391+ }
392+ } else {
393+ siteEnvelope .Properties .VnetImagePullEnabled = pointer .To (webAppSlot .VirtualNetworkImagePullEnabled )
394+ }
395+
363396 if differentServicePlanToParent {
364397 siteEnvelope .Properties .ServerFarmId = pointer .To (servicePlanId .ID ())
365398 }
@@ -633,6 +666,7 @@ func (r WindowsWebAppSlotResource) Read() sdk.ResourceFunc {
633666 state .PossibleOutboundIPAddressList = strings .Split (pointer .From (props .PossibleOutboundIPAddresses ), "," )
634667 state .PublicNetworkAccess = ! strings .EqualFold (pointer .From (props .PublicNetworkAccess ), helpers .PublicNetworkAccessDisabled )
635668 state .VirtualNetworkBackupRestoreEnabled = pointer .From (props .VnetBackupRestoreEnabled )
669+ state .VirtualNetworkImagePullEnabled = pointer .From (props .VnetImagePullEnabled )
636670
637671 if hostingEnv := props .HostingEnvironmentProfile ; hostingEnv != nil {
638672 hostingEnvId , err := parse .AppServiceEnvironmentIDInsensitively (* hostingEnv .Id )
@@ -861,6 +895,10 @@ func (r WindowsWebAppSlotResource) Update() sdk.ResourceFunc {
861895 model .Properties .VnetBackupRestoreEnabled = pointer .To (state .VirtualNetworkBackupRestoreEnabled )
862896 }
863897
898+ if metadata .ResourceData .HasChange ("virtual_network_image_pull_enabled" ) {
899+ model .Properties .VnetImagePullEnabled = pointer .To (state .VirtualNetworkImagePullEnabled )
900+ }
901+
864902 if metadata .ResourceData .HasChange ("virtual_network_subnet_id" ) {
865903 subnetId := metadata .ResourceData .Get ("virtual_network_subnet_id" ).(string )
866904 if subnetId == "" {
@@ -1021,3 +1059,48 @@ func (r WindowsWebAppSlotResource) StateUpgraders() sdk.StateUpgradeData {
10211059 },
10221060 }
10231061}
1062+
1063+ func (r WindowsWebAppSlotResource ) CustomizeDiff () sdk.ResourceFunc {
1064+ return sdk.ResourceFunc {
1065+ Timeout : 5 * time .Minute ,
1066+ Func : func (ctx context.Context , metadata sdk.ResourceMetaData ) error {
1067+ client := metadata .Client .AppService .WebAppsClient
1068+
1069+ model := WindowsWebAppSlotModel {}
1070+ if err := metadata .DecodeDiff (& model ); err != nil {
1071+ return fmt .Errorf ("decoding: %w" , err )
1072+ }
1073+
1074+ if metadata .ResourceDiff .HasChange ("virtual_network_image_pull_enabled" ) {
1075+ appServiceId := model .AppServiceId
1076+ if appServiceId == "" {
1077+ return nil
1078+ }
1079+
1080+ _ , newValue := metadata .ResourceDiff .GetChange ("virtual_network_image_pull_enabled" )
1081+ if newValue .(bool ) {
1082+ return nil
1083+ }
1084+
1085+ appServiceID , err := commonids .ParseAppServiceID (appServiceId )
1086+ if err != nil {
1087+ return err
1088+ }
1089+
1090+ resp , err := client .Get (ctx , * appServiceID )
1091+ if err != nil {
1092+ return fmt .Errorf ("retrieving %s: %w" , * appServiceID , err )
1093+ }
1094+
1095+ if webAppModel := resp .Model ; webAppModel != nil {
1096+ if webAppModel .Properties != nil && webAppModel .Properties .HostingEnvironmentProfile != nil &&
1097+ pointer .From (webAppModel .Properties .HostingEnvironmentProfile .Id ) != "" && ! newValue .(bool ) {
1098+ return fmt .Errorf ("`virtual_network_image_pull_enabled` cannot be disabled for app running in an app service environment" )
1099+ }
1100+ }
1101+ }
1102+
1103+ return nil
1104+ },
1105+ }
1106+ }
0 commit comments