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 16, 2023
1 parent a4e9c91 commit 93cafe5
Show file tree
Hide file tree
Showing 67 changed files with 204 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
79 changes: 77 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 @@ -178,8 +188,37 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {
},
},
},
"scaling": {
Type: pluginsdk.TypeList,
Required: 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 +261,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 +321,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 +428,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 +497,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 = "test@test.com"
}
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 = "testing@test.com"
}
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 93cafe5

Please sign in to comment.