From 427e7b226a9fcf006e02de9470dc650d47867061 Mon Sep 17 00:00:00 2001 From: sarna Date: Sun, 11 Feb 2024 15:28:41 -0700 Subject: [PATCH] Add Upgrade Channels to NGINXaaS --- .../nginx/nginx_deployment_data_source.go | 10 ++++++++ .../nginx_deployment_data_source_test.go | 1 + .../nginx/nginx_deployment_resource.go | 24 +++++++++++++++++++ .../nginx/nginx_deployment_resource_test.go | 11 +++++---- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/internal/services/nginx/nginx_deployment_data_source.go b/internal/services/nginx/nginx_deployment_data_source.go index 4d38ae5864f4d..7e491fb9c1b2e 100644 --- a/internal/services/nginx/nginx_deployment_data_source.go +++ b/internal/services/nginx/nginx_deployment_data_source.go @@ -34,6 +34,7 @@ type DeploymentDataSourceModel struct { FrontendPublic []FrontendPublic `tfschema:"frontend_public"` FrontendPrivate []FrontendPrivate `tfschema:"frontend_private"` NetworkInterface []NetworkInterface `tfschema:"network_interface"` + UpgradeChannel string `tfschema:"automatic_upgrade_channel"` Tags map[string]string `tfschema:"tags"` } @@ -164,6 +165,11 @@ func (m DeploymentDataSource) Attributes() map[string]*pluginsdk.Schema { }, }, + "automatic_upgrade_channel": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "tags": commonschema.TagsDataSource(), } } @@ -267,6 +273,10 @@ func (m DeploymentDataSource) Read() sdk.ResourceFunc { if userProfile := props.UserProfile; userProfile != nil && userProfile.PreferredEmail != nil { output.Email = pointer.ToString(props.UserProfile.PreferredEmail) } + + if autoUpgradeProfile := props.AutoUpgradeProfile; autoUpgradeProfile != nil { + output.UpgradeChannel = props.AutoUpgradeProfile.UpgradeChannel + } } } diff --git a/internal/services/nginx/nginx_deployment_data_source_test.go b/internal/services/nginx/nginx_deployment_data_source_test.go index 174fbe294808c..757f05783b4f7 100644 --- a/internal/services/nginx/nginx_deployment_data_source_test.go +++ b/internal/services/nginx/nginx_deployment_data_source_test.go @@ -27,6 +27,7 @@ func TestAccNginxDeploymentDataSource_basic(t *testing.T) { check.That(data.ResourceName).Key("capacity").Exists(), check.That(data.ResourceName).Key("managed_resource_group").Exists(), check.That(data.ResourceName).Key("ip_address").Exists(), + check.That(data.ResourceName).Key("automatic_upgrade_channel").Exists(), ), }, }) diff --git a/internal/services/nginx/nginx_deployment_resource.go b/internal/services/nginx/nginx_deployment_resource.go index bca153fb9ec8d..f55f07ea4ec0a 100644 --- a/internal/services/nginx/nginx_deployment_resource.go +++ b/internal/services/nginx/nginx_deployment_resource.go @@ -53,6 +53,7 @@ type DeploymentModel struct { FrontendPublic []FrontendPublic `tfschema:"frontend_public"` FrontendPrivate []FrontendPrivate `tfschema:"frontend_private"` NetworkInterface []NetworkInterface `tfschema:"network_interface"` + UpgradeChannel string `tfschema:"automatic_upgrade_channel"` Tags map[string]string `tfschema:"tags"` } @@ -194,6 +195,13 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema { }, }, + "automatic_upgrade_channel": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "stable", + ValidateFunc: validation.StringIsNotEmpty, + }, + "tags": commonschema.Tags(), } } @@ -309,6 +317,12 @@ func (m DeploymentResource) Create() sdk.ResourceFunc { } } + if model.UpgradeChannel != "" { + prop.AutoUpgradeProfile = &nginxdeployment.AutoUpgradeProfile{ + UpgradeChannel: model.UpgradeChannel, + } + } + req.Properties = prop req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity) @@ -412,6 +426,10 @@ func (m DeploymentResource) Read() sdk.ResourceFunc { output.Email = pointer.ToString(props.UserProfile.PreferredEmail) } + if autoUpgradeProfile := props.AutoUpgradeProfile; autoUpgradeProfile != nil { + output.UpgradeChannel = props.AutoUpgradeProfile.UpgradeChannel + } + flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMapToModel(model.Identity) if err != nil { return fmt.Errorf("flattening `identity`: %v", err) @@ -481,6 +499,12 @@ func (m DeploymentResource) Update() sdk.ResourceFunc { } } + if meta.ResourceData.HasChange("automatic_upgrade_channel") { + req.Properties.AutoUpgradeProfile = &nginxdeployment.AutoUpgradeProfile{ + UpgradeChannel: model.UpgradeChannel, + } + } + if err := client.DeploymentsUpdateThenPoll(ctx, *id, req); err != nil { return fmt.Errorf("updating %s: %v", id, err) } diff --git a/internal/services/nginx/nginx_deployment_resource_test.go b/internal/services/nginx/nginx_deployment_resource_test.go index 39211e2b46697..7234c3dfd480b 100644 --- a/internal/services/nginx/nginx_deployment_resource_test.go +++ b/internal/services/nginx/nginx_deployment_resource_test.go @@ -105,11 +105,12 @@ func (a DeploymentResource) basic(data acceptance.TestData) string { %s resource "azurerm_nginx_deployment" "test" { - name = "acctest-%[2]d" - resource_group_name = azurerm_resource_group.test.name - sku = "standard_Monthly" - location = azurerm_resource_group.test.location - diagnose_support_enabled = true + name = "acctest-%[2]d" + resource_group_name = azurerm_resource_group.test.name + sku = "standard_Monthly" + location = azurerm_resource_group.test.location + diagnose_support_enabled = true + automatic_upgrade_channel = "stable" frontend_public { ip_address = [azurerm_public_ip.test.id]