Referencing indexes in Python

For resources that are lists, such as Azure FunctionAppIdentity, how do you reference indexes properly in Python? For example:

function = FunctionApp(self, ... identity=[FunctionAppIdentity(type="SystemAssigned")], ...

# this is how you'd ref the identity principal_id in HCL: 
# azurerm_function_app.function.identity.0.principal_id

# this errors with raise AttributeError("'%s' object has no attribute '%s'" % (type_info, name))
object_id = function.identity[0].principal_id

Sorry for the delayed response. This appears to be a bug specific to principal_id and other nested block properties that can’t be set.

It would be great if you could file an issue so that you get updates on progress made towards fixing this.

Thank you @jsteinich for the response. I have run into this for other resources, so just assumed I was referencing incorrectly. I will file an issue.

There are times where you’ll need to use tokens, but ideally how you’re referencing things should work.

The principal_id property doesn’t exist on the generated FunctionAppIdentity so it isn’t directly referenceable. This is pretty similar to, but is slightly different in that some properties actually do exist for configuration.

If you are still stuck on this, it should be possible to use an escape hatch to reference it.