05/25/2021, 11:45 AM
Hi folks, I've got a question about chaining providers in Python. My code has three providers (AWS) in total, most of the code runs with the default provider. I then create an iam role which the second provider assumes. This one I call intermediate, because it is just used to assume into the target account to create the last ressources over there. Or should I say I hoped to do so, because my code failes.
current_region = aws.get_region()
intermediate_provider = aws.Provider("IntermediateProvider",,
                        assume_role={'role_arn': created_role.arn, 'session_name': 'abc'})
target_provider = aws.Provider("TargetProvider",,
                        assume_role={'role_arn': external_role.arn, 'session_name': 'def'},

some_ressource = aws.ec2...(opts=ResourceOptions(provider=target_provider))
This code fails with an ominous error message:
TypeError: Explicit providers may not be used with provider resources
This code excerpt is a rewrite of an existing Go codebase for another team, that uses Python. So I knew and thus expected the code to work
I found a solution for the problem, even though I do not understand why it works 😉
Changing the ResourceOptions for the target_provider from (provider=intermediate_provider) to (provider*s*=*[intermediate_provider]*)
So, many words later, here the proposed question, why can't I chain providers in Pulumi using Python? Or why can't I use them the way I expected them to work?
If this is expected behaviour should we add an aws-py-chained-providers to the example repository?