diff --git a/internal/services/nginx/nginx_deployment_resource.go b/internal/services/nginx/nginx_deployment_resource.go index 8f03e7a72772..f907214c020d 100644 --- a/internal/services/nginx/nginx_deployment_resource.go +++ b/internal/services/nginx/nginx_deployment_resource.go @@ -45,7 +45,9 @@ type DeploymentModel struct { Sku string `tfschema:"sku"` ManagedResourceGroup string `tfschema:"managed_resource_group"` Location string `tfschema:"location"` + Capacity int64 `tfschema:"capacity"` DiagnoseSupportEnabled bool `tfschema:"diagnose_support_enabled"` + Email string `tfschema:"email"` IpAddress string `tfschema:"ip_address"` LoggingStorageAccount []LoggingStorageAccount `tfschema:"logging_storage_account"` FrontendPublic []FrontendPublic `tfschema:"frontend_public"` @@ -95,12 +97,24 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema { "location": commonschema.Location(), + "capacity": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntPositive, + }, + "diagnose_support_enabled": { Type: pluginsdk.TypeBool, Optional: true, ValidateFunc: nil, }, + "email": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "logging_storage_account": { Type: pluginsdk.TypeList, Optional: true, @@ -222,7 +236,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) } @@ -282,6 +296,18 @@ func (m DeploymentResource) Create() sdk.ResourceFunc { prop.NetworkProfile.NetworkInterfaceConfiguration.SubnetId = pointer.FromString(model.NetworkInterface[0].SubnetId) } + if model.Capacity > 0 { + prop.ScalingProperties = &nginxdeployment.NginxDeploymentScalingProperties{ + Capacity: pointer.FromInt64(model.Capacity), + } + } + + if model.Email != "" { + prop.UserProfile = &nginxdeployment.NginxDeploymentUserProfile{ + PreferredEmail: pointer.FromString(model.Email), + } + } + req.Properties = prop req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity) @@ -377,6 +403,14 @@ func (m DeploymentResource) Read() sdk.ResourceFunc { } } + if scaling := props.ScalingProperties; scaling != nil { + output.Capacity = pointer.ToInt64(props.ScalingProperties.Capacity) + } + + if userProfile := props.UserProfile; userProfile != nil && userProfile.PreferredEmail != nil { + output.Email = pointer.ToString(props.UserProfile.PreferredEmail) + } + flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMapToModel(model.Identity) if err != nil { return fmt.Errorf("flattening `identity`: %v", err) @@ -434,6 +468,18 @@ func (m DeploymentResource) Update() sdk.ResourceFunc { req.Properties.EnableDiagnosticsSupport = pointer.FromBool(model.DiagnoseSupportEnabled) } + if meta.ResourceData.HasChange("capacity") && model.Capacity > 0 { + req.Properties.ScalingProperties = &nginxdeployment.NginxDeploymentScalingProperties{ + Capacity: pointer.FromInt64(model.Capacity), + } + } + + if meta.ResourceData.HasChange("email") { + req.Properties.UserProfile = &nginxdeployment.NginxDeploymentUserProfile{ + PreferredEmail: pointer.FromString(model.Email), + } + } + 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 48e9a1cb4df6..2508e265b94c 100644 --- a/internal/services/nginx/nginx_deployment_resource_test.go +++ b/internal/services/nginx/nginx_deployment_resource_test.go @@ -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("capacity").HasValue("10"), + check.That(data.ResourceName).Key("email").HasValue("test@test.com"), ), }, data.ImportStep(), @@ -84,6 +86,8 @@ func (a DeploymentResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` + + %s resource "azurerm_nginx_deployment" "test" { @@ -100,6 +104,11 @@ resource "azurerm_nginx_deployment" "test" { network_interface { subnet_id = azurerm_subnet.test.id } + + capacity = 10 + + email = "test@test.com" + tags = { foo = "bar" } @@ -128,6 +137,10 @@ resource "azurerm_nginx_deployment" "test" { subnet_id = azurerm_subnet.test.id } + capacity = 20 + + email = "testing@test.com" + tags = { foo = "bar2" } @@ -165,6 +178,10 @@ resource "azurerm_nginx_deployment" "test" { network_interface { subnet_id = azurerm_subnet.test.id } + + capacity = 10 + + email = "test@test.com" } `, a.template(data), data.RandomInteger) } diff --git a/website/docs/r/nginx_deployment.html.markdown b/website/docs/r/nginx_deployment.html.markdown index 5f438ded153a..2c8ce3c474c6 100644 --- a/website/docs/r/nginx_deployment.html.markdown +++ b/website/docs/r/nginx_deployment.html.markdown @@ -68,6 +68,10 @@ resource "azurerm_nginx_deployment" "example" { network_interface { subnet_id = azurerm_subnet.example.id } + + capacity = 20 + + email = "user@test.com" } ``` @@ -87,8 +91,14 @@ The following arguments are supported: --- +* `capacity` - (Optional) Specify the number of NGINX capacity units for this NGINX deployment. + +-> **Note** For more information on NGINX capacity units, please refer to the [NGINX scaling guidance documentation](https://docs.nginx.com/nginxaas/azure/quickstart/scaling/) + * `diagnose_support_enabled` - (Optional) Should the diagnosis support be enabled? +* `email` - (Optional) Specify the preferred support contact email address of the user used for sending alerts and notification. + * `identity` - (Optional) An `identity` block as defined below. * `frontend_private` - (Optional) One or more `frontend_private` blocks as defined below. Changing this forces a new Nginx Deployment to be created. @@ -139,6 +149,7 @@ A `network_interface` block supports the following: * `subnet_id` - (Required) Specify The SubNet Resource ID to this Nginx Deployment. + ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: