Skip to content

Commit

Permalink
Updated azurerm_nginx_deployment to support latest API changes (scali…
Browse files Browse the repository at this point in the history
…ng & user_profile)

Bumped API version from 2022-08-01 to 2023-04-01
  • Loading branch information
agazeley committed Oct 17, 2023
1 parent f606659 commit cdb7f3e
Show file tree
Hide file tree
Showing 67 changed files with 207 additions and 57 deletions.
2 changes: 1 addition & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
dns_v2018_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01"
eventgrid_v2022_06_15 "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2022-06-15"
fluidrelay_2022_05_26 "github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26"
nginx2 "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01"
nginx2 "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01"
redis_v2023_04_01 "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2023-04-01"
servicenetworking_v2023_05_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-05-01-preview"
storagecache_2023_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/storagecache/2023-05-01"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/nginx/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package client
import (
"fmt"

nginx "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01"
nginx "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/services/nginx/nginx_certificate_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
keyvaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/nginx/nginx_certificate_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxcertificate"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
4 changes: 2 additions & 2 deletions internal/services/nginx/nginx_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxconfiguration"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
80 changes: 78 additions & 2 deletions internal/services/nginx/nginx_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -37,6 +37,14 @@ type NetworkInterface struct {
SubnetId string `tfschema:"subnet_id"`
}

type ScalingProperties struct {
Capacity int64 `tfschema:"capacity"`
}

type UserProfile struct {
PreferredEmail string `tfschema:"preferred_email"`
}

type DeploymentModel struct {
ResourceGroupName string `tfschema:"resource_group_name"`
Name string `tfschema:"name"`
Expand All @@ -51,7 +59,9 @@ type DeploymentModel struct {
FrontendPublic []FrontendPublic `tfschema:"frontend_public"`
FrontendPrivate []FrontendPrivate `tfschema:"frontend_private"`
NetworkInterface []NetworkInterface `tfschema:"network_interface"`
ScalingProperties []ScalingProperties `tfschema:"scaling"`
Tags map[string]string `tfschema:"tags"`
UserProfile []UserProfile `tfschema:"user_profile"`
}

type DeploymentResource struct{}
Expand Down Expand Up @@ -179,7 +189,37 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {
},
},

"scaling": {
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: false,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"capacity": {
Type: pluginsdk.TypeInt,
Required: true,
ValidateFunc: validation.IntPositive,
},
},
},
},

"tags": commonschema.Tags(),

"user_profile": {
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: false,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"preferred_email": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
}
}

Expand Down Expand Up @@ -222,7 +262,7 @@ func (m DeploymentResource) Create() sdk.ResourceFunc {

if !response.WasNotFound(existing.HttpResponse) {
if err != nil {
return fmt.Errorf("retreiving %s: %v", id, err)
return fmt.Errorf("retrieving %s: %v", id, err)
}
return meta.ResourceRequiresImport(m.ResourceType(), id)
}
Expand Down Expand Up @@ -282,6 +322,18 @@ func (m DeploymentResource) Create() sdk.ResourceFunc {
prop.NetworkProfile.NetworkInterfaceConfiguration.SubnetId = pointer.FromString(model.NetworkInterface[0].SubnetId)
}

if len(model.ScalingProperties) > 0 {
prop.ScalingProperties = &nginxdeployment.NginxDeploymentScalingProperties{
Capacity: pointer.FromInt64(model.ScalingProperties[0].Capacity),
}
}

if len(model.UserProfile) > 0 && model.UserProfile[0].PreferredEmail != "" {
prop.UserProfile = &nginxdeployment.NginxDeploymentUserProfile{
PreferredEmail: &model.UserProfile[0].PreferredEmail,
}
}

req.Properties = prop

req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity)
Expand Down Expand Up @@ -377,6 +429,18 @@ func (m DeploymentResource) Read() sdk.ResourceFunc {
}
}

if scaling := props.ScalingProperties; scaling != nil {
output.ScalingProperties = []ScalingProperties{{
Capacity: pointer.ToInt64(props.ScalingProperties.Capacity),
}}
}

if userProfile := props.UserProfile; userProfile != nil && userProfile.PreferredEmail != nil {
output.UserProfile = []UserProfile{{
PreferredEmail: pointer.ToString(props.UserProfile.PreferredEmail),
}}
}

flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMapToModel(model.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %v", err)
Expand Down Expand Up @@ -434,6 +498,18 @@ func (m DeploymentResource) Update() sdk.ResourceFunc {
req.Properties.EnableDiagnosticsSupport = pointer.FromBool(model.DiagnoseSupportEnabled)
}

if meta.ResourceData.HasChange("scaling") && len(model.ScalingProperties) > 0 {
req.Properties.ScalingProperties = &nginxdeployment.NginxDeploymentScalingProperties{
Capacity: pointer.FromInt64(model.ScalingProperties[0].Capacity),
}
}

if meta.ResourceData.HasChange("user_profile") && len(model.UserProfile) > 0 {
req.Properties.UserProfile = &nginxdeployment.NginxDeploymentUserProfile{
PreferredEmail: pointer.FromString(model.UserProfile[0].PreferredEmail),
}
}

if err := client.DeploymentsUpdateThenPoll(ctx, *id, req); err != nil {
return fmt.Errorf("updating %s: %v", id, err)
}
Expand Down
31 changes: 30 additions & 1 deletion internal/services/nginx/nginx_deployment_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-04-01/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -39,6 +39,8 @@ func TestAccNginxDeployment_basic(t *testing.T) {
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("scaling").HasValue("10"),
check.That(data.ResourceName).Key("user_profile").Exists(),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -84,6 +86,8 @@ func (a DeploymentResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_nginx_deployment" "test" {
Expand All @@ -100,6 +104,15 @@ resource "azurerm_nginx_deployment" "test" {
network_interface {
subnet_id = azurerm_subnet.test.id
}
scaling {
capacity = 10
}
user_profile {
preferred_email = "[email protected]"
}
tags = {
foo = "bar"
}
Expand All @@ -111,6 +124,8 @@ func (a DeploymentResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_nginx_deployment" "test" {
Expand All @@ -128,6 +143,14 @@ resource "azurerm_nginx_deployment" "test" {
subnet_id = azurerm_subnet.test.id
}
scaling {
capacity = 20
}
user_profile {
preferred_email = "[email protected]"
}
tags = {
foo = "bar2"
}
Expand All @@ -139,6 +162,8 @@ func (a DeploymentResource) identityUser(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_user_assigned_identity" "test" {
Expand All @@ -165,6 +190,10 @@ resource "azurerm_nginx_deployment" "test" {
network_interface {
subnet_id = azurerm_subnet.test.id
}
scaling {
capacity = 10
}
}
`, a.template(data), data.RandomInteger)
}
Expand Down

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cdb7f3e

Please sign in to comment.