Skip to content

Commit ef05a00

Browse files
authored
azurerm_nginx_deployment: Update code and docs to allow System Assigned Identity (#24382)
- NGINXaaS for Azure supports system managed identity. - Added a test to exercise system MI.
1 parent dafac44 commit ef05a00

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

internal/services/nginx/nginx_deployment_resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {
8383
}, false),
8484
},
8585

86-
// only UserIdentity supported, but api defined as SystemAndUserAssigned
87-
// issue link: https://github.com/Azure/azure-rest-api-specs/issues/20914
86+
// only one type of identity is supported.
8887
"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),
8988

9089
"managed_resource_group": {
@@ -313,7 +312,7 @@ func (m DeploymentResource) Create() sdk.ResourceFunc {
313312

314313
req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity)
315314
if err != nil {
316-
return fmt.Errorf("expanding user identities: %+v", err)
315+
return fmt.Errorf("expanding identities: %+v", err)
317316
}
318317

319318
err = client.DeploymentsCreateOrUpdateThenPoll(ctx, id, req)
@@ -451,7 +450,7 @@ func (m DeploymentResource) Update() sdk.ResourceFunc {
451450

452451
if meta.ResourceData.HasChange("identity") {
453452
if req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity); err != nil {
454-
return fmt.Errorf("expanding user identities: %+v", err)
453+
return fmt.Errorf("expanding identities: %+v", err)
455454
}
456455
}
457456

internal/services/nginx/nginx_deployment_resource_test.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,26 @@ func TestAccNginxDeployment_update(t *testing.T) {
6868
})
6969
}
7070

71-
func TestAccNginxDeployment_identity(t *testing.T) {
71+
func TestAccNginxDeployment_systemAssignedIdentity(t *testing.T) {
7272
data := acceptance.BuildTestData(t, nginx.DeploymentResource{}.ResourceType(), "test")
7373
r := DeploymentResource{}
7474
data.ResourceTest(t, r, []acceptance.TestStep{
7575
{
76-
Config: r.identityUser(data),
76+
Config: r.systemAssignedIdentity(data),
77+
Check: acceptance.ComposeTestCheckFunc(
78+
check.That(data.ResourceName).ExistsInAzure(r),
79+
),
80+
},
81+
data.ImportStep(),
82+
})
83+
}
84+
85+
func TestAccNginxDeployment_userAssignedIdentity(t *testing.T) {
86+
data := acceptance.BuildTestData(t, nginx.DeploymentResource{}.ResourceType(), "test")
87+
r := DeploymentResource{}
88+
data.ResourceTest(t, r, []acceptance.TestStep{
89+
{
90+
Config: r.userAssignedIdentity(data),
7791
Check: acceptance.ComposeTestCheckFunc(
7892
check.That(data.ResourceName).ExistsInAzure(r),
7993
),
@@ -148,7 +162,38 @@ resource "azurerm_nginx_deployment" "test" {
148162
`, a.template(data), data.RandomInteger)
149163
}
150164

151-
func (a DeploymentResource) identityUser(data acceptance.TestData) string {
165+
func (a DeploymentResource) systemAssignedIdentity(data acceptance.TestData) string {
166+
return fmt.Sprintf(`
167+
168+
169+
%s
170+
171+
resource "azurerm_nginx_deployment" "test" {
172+
name = "acctest-%[2]d"
173+
resource_group_name = azurerm_resource_group.test.name
174+
sku = "standard_Monthly"
175+
location = azurerm_resource_group.test.location
176+
177+
identity {
178+
type = "SystemAssigned"
179+
}
180+
181+
frontend_public {
182+
ip_address = [azurerm_public_ip.test.id]
183+
}
184+
185+
network_interface {
186+
subnet_id = azurerm_subnet.test.id
187+
}
188+
189+
capacity = 10
190+
191+
192+
}
193+
`, a.template(data), data.RandomInteger)
194+
}
195+
196+
func (a DeploymentResource) userAssignedIdentity(data acceptance.TestData) string {
152197
return fmt.Sprintf(`
153198
154199

website/docs/r/nginx_deployment.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ The following arguments are supported:
115115

116116
A `identity` block supports the following:
117117

118-
* `type` - (Required) Specifies the identity type of the Nginx Deployment. Possible values is `UserAssigned` where you can specify the Service Principal IDs in the `identity_ids` field.
118+
* `type` - (Required) Specifies the identity type of the Nginx Deployment. Possible values are `UserAssigned`, `SystemAssigned`.
119119

120-
* `identity_ids` - (Optional) Specifies a list of user managed identity ids to be assigned. Required if `type` is `UserAssigned`.
120+
* `identity_ids` - (Optional) Specifies a list of user managed identity ids to be assigned.
121+
122+
~> **NOTE:** This is required when `type` is set to `UserAssigned`.
121123

122124
---
123125

0 commit comments

Comments
 (0)