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

azurerm_nginx_deployment: Update code and docs to allow System Assigned Identity #24382

Merged
merged 1 commit into from
Jan 4, 2024
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
7 changes: 3 additions & 4 deletions internal/services/nginx/nginx_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {
}, false),
},

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

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

req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity)
if err != nil {
return fmt.Errorf("expanding user identities: %+v", err)
return fmt.Errorf("expanding identities: %+v", err)
}

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

if meta.ResourceData.HasChange("identity") {
if req.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity); err != nil {
return fmt.Errorf("expanding user identities: %+v", err)
return fmt.Errorf("expanding identities: %+v", err)
}
}

Expand Down
51 changes: 48 additions & 3 deletions internal/services/nginx/nginx_deployment_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,26 @@ func TestAccNginxDeployment_update(t *testing.T) {
})
}

func TestAccNginxDeployment_identity(t *testing.T) {
func TestAccNginxDeployment_systemAssignedIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, nginx.DeploymentResource{}.ResourceType(), "test")
r := DeploymentResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.identityUser(data),
Config: r.systemAssignedIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccNginxDeployment_userAssignedIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, nginx.DeploymentResource{}.ResourceType(), "test")
r := DeploymentResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.userAssignedIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand Down Expand Up @@ -148,7 +162,38 @@ resource "azurerm_nginx_deployment" "test" {
`, a.template(data), data.RandomInteger)
}

func (a DeploymentResource) identityUser(data acceptance.TestData) string {
func (a DeploymentResource) systemAssignedIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`


%s

resource "azurerm_nginx_deployment" "test" {
name = "acctest-%[2]d"
resource_group_name = azurerm_resource_group.test.name
sku = "standard_Monthly"
location = azurerm_resource_group.test.location

identity {
type = "SystemAssigned"
}

frontend_public {
ip_address = [azurerm_public_ip.test.id]
}

network_interface {
subnet_id = azurerm_subnet.test.id
}

capacity = 10

email = "[email protected]"
}
`, a.template(data), data.RandomInteger)
}

func (a DeploymentResource) userAssignedIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`


Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/nginx_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ The following arguments are supported:

A `identity` block supports the following:

* `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.
* `type` - (Required) Specifies the identity type of the Nginx Deployment. Possible values are `UserAssigned`, `SystemAssigned`.

* `identity_ids` - (Optional) Specifies a list of user managed identity ids to be assigned. Required if `type` is `UserAssigned`.
* `identity_ids` - (Optional) Specifies a list of user managed identity ids to be assigned.

~> **NOTE:** This is required when `type` is set to `UserAssigned`.

---

Expand Down
Loading