Skip to content

Commit

Permalink
Updated to support latest API changes (scaling & user_profile)
Browse files Browse the repository at this point in the history
  • Loading branch information
agazeley committed Oct 16, 2023
1 parent 7d72bc0 commit 25698ac
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 11 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 @@ -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,19 @@ 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),
}
}

// Ignore updates? Need to inquire
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
25 changes: 24 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 @@ -100,6 +102,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 Down Expand Up @@ -128,6 +139,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 Down Expand Up @@ -165,6 +184,10 @@ resource "azurerm_nginx_deployment" "test" {
network_interface {
subnet_id = azurerm_subnet.test.id
}
scaling {
capacity = 10
}
}
`, a.template(data), data.RandomInteger)
}
Expand Down
24 changes: 24 additions & 0 deletions website/docs/r/nginx_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ resource "azurerm_nginx_deployment" "example" {
network_interface {
subnet_id = azurerm_subnet.example.id
}
scaling {
capacity = 20
}
user_profile {
preferred_email = "user@test.com"
}
}
```

Expand Down Expand Up @@ -99,8 +107,12 @@ The following arguments are supported:

* `network_interface` - (Optional) One or more `network_interface` blocks as defined below. Changing this forces a new Nginx Deployment to be created.

* `scaling` - One or more `scaling` blocks as defined below.

* `tags` - (Optional) A mapping of tags which should be assigned to the Nginx Deployment.

* `user_profile` - (Optional) One or more `user_profile` blocks as defined below.

---

A `identity` block supports the following:
Expand Down Expand Up @@ -139,6 +151,18 @@ A `network_interface` block supports the following:

* `subnet_id` - (Required) Specify The SubNet Resource ID to this Nginx Deployment.

---

A `scaling` block supports the following:

* `capacity` - (Required) Specify the number of NGINX capacity units for this Nginx Deployment.

---

A `user_profile` block supports the following:

* `preferred_email` - (Required) Specify the preferred support contact email address of the user used for sending alerts and notification.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand Down

0 comments on commit 25698ac

Please sign in to comment.