pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
125 stars 34 forks source link

Fix the `identity` field in the Golang `dbforpostgresql.Server` example documentation #3324

Open zbuchheit opened 4 months ago

zbuchheit commented 4 months ago

What happened?

When attempting to user a UserAssignedIdentity with dbforpostgresql.Server in Golang here, a user ran into issues and wasn't able to get the example from ServerCreatewithDataEncryptionEnabled to work properly.

Example

This example from the documentation doesn't work as intended

            Identity: &dbforpostgresql.UserAssignedIdentityArgs{
                Type: pulumi.String(dbforpostgresql.IdentityTypeUserAssigned),
                UserAssignedIdentities: dbforpostgresql.UserIdentityMap{
                    "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testresourcegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-usermanagedidentity": nil,
                },
            },

while this is what I was able get to work for the user

            Identity: &dbforpostgresql.UserAssignedIdentityArgs{
                Type: pulumi.String(dbforpostgresql.IdentityTypeUserAssigned),
                UserAssignedIdentities: userAssignedIdentity.ID().ApplyT(func(id string) (dbforpostgresql.UserIdentityMap) {
                    return dbforpostgresql.UserIdentityMap{
                        id: dbforpostgresql.UserIdentityArgs{},
                    }
                }).(dbforpostgresql.UserIdentityMapOutput),
            },

Output of pulumi about

CLI          
Version      3.117.0
Go Version   go1.22.3
Go Compiler  gc

Plugins
KIND      NAME          VERSION
resource  azure-native  2.43.0
resource  azure-native  2.43.0
resource  azure-native  2.43.0
resource  azure-native  2.42.1
resource  azure-native  2.42.1
language  go            unknown

Host     
OS       darwin
Version  14.2.1
Arch     arm64

This project is written in go: executable='/opt/homebrew/bin/go' version='go version go1.22.3 darwin/arm64'

Current Stack: zbuchheit-pulumi-corp/azure-postgresql-go/dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/zbuchheit-pulumi-corp
User           zbuchheit-pulumi-corp
Organizations  zbuchheit-pulumi-corp
Token type     personal

Dependencies:
NAME                                                          VERSION
github.com/pulumi/pulumi-azure-native-sdk/dbforpostgresql/v2  v2.43.0
github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2  v2.43.0
github.com/pulumi/pulumi-azure-native-sdk/resources/v2        v2.42.1
github.com/pulumi/pulumi-azure-native-sdk/storage/v2          v2.42.1
github.com/pulumi/pulumi/sdk/v3                               v3.117.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

thomas11 commented 4 months ago

Hey @zbuchheit, the example you quoted looks like it's not in Go. Did you activate the "Go" tab under "Example Usage"?

The Go example in the docs is

            Identity: &dbforpostgresql.UserAssignedIdentityArgs{
                Type: pulumi.String(dbforpostgresql.IdentityTypeUserAssigned),
                UserAssignedIdentities: dbforpostgresql.UserIdentityMap{
                    "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testresourcegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-usermanagedidentity": nil,
                },
            },

This seems identical to your working code, except that you need an apply to access userAssignedIdentity.ID().

I'm not sure why you need the .(dbforpostgresql.UserIdentityMapOutput) at the end.

zbuchheit commented 4 months ago

Whoops, sorry was multitasking and accidentally copied over the typescript example, I updated the issue. I believe the difference lies here with id: dbforpostgresql.UserIdentityArgs{}, vs id: nil,. When I tried nil it wasn't working as desired.

mikhailshilkov commented 2 weeks ago

@danielrbradley Do you know why this resource still has the old weird structure of userAssignedIdentities and wasn't improved in https://github.com/pulumi/pulumi-azure-native/pull/1833?

danielrbradley commented 2 weeks ago

@mikhailshilkov it looks like a mistake in the specs for this resource where the client id and principle id are marked as inputtable by the user, so we honnor this and generate an input type for the fields and don't flattern the map into a string set.