Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated azurerm_nginx_deployment to support latest API properties #23596

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion internal/services/nginx/nginx_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -95,12 +97,24 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {

"location": commonschema.Location(),

"capacity": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.IntPositive,
catriona-m marked this conversation as resolved.
Show resolved Hide resolved
},

"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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
17 changes: 17 additions & 0 deletions internal/services/nginx/nginx_deployment_resource_test.go
Original file line number Diff line number Diff line change
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("capacity").HasValue("10"),
check.That(data.ResourceName).Key("email").HasValue("[email protected]"),
),
},
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,11 @@ resource "azurerm_nginx_deployment" "test" {
network_interface {
subnet_id = azurerm_subnet.test.id
}

capacity = 10

email = "[email protected]"

tags = {
foo = "bar"
}
Expand Down Expand Up @@ -128,6 +137,10 @@ resource "azurerm_nginx_deployment" "test" {
subnet_id = azurerm_subnet.test.id
}

capacity = 20

email = "[email protected]"

tags = {
foo = "bar2"
}
Expand Down Expand Up @@ -165,6 +178,10 @@ resource "azurerm_nginx_deployment" "test" {
network_interface {
subnet_id = azurerm_subnet.test.id
}

capacity = 10

email = "[email protected]"
}
`, a.template(data), data.RandomInteger)
}
Expand Down
11 changes: 11 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,10 @@ resource "azurerm_nginx_deployment" "example" {
network_interface {
subnet_id = azurerm_subnet.example.id
}

capacity = 20

email = "[email protected]"
}
```

Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
Loading