https://pulumi.com logo
#getting-started
Title
# getting-started
a

able-energy-34495

05/04/2023, 8:44 PM
Hey guys, I wrote a class that creates AWS resources to create backups of EC2 instances. It's just a simple test but fails when it trys to run the method aws.iam.get_policy_document(). "AttributeError: 'NoneType' object has no attribute 'id'" The module deploys the real infrastructure fine, but attempting to test it is giving me this error. Anyone able to assist?
Copy code
# create assume role policy for backup role
        self.role_policy = aws.iam.get_policy_document(
            statements=[
                aws.iam.GetPolicyDocumentStatementArgs(
                    effect="Allow",
                    principals=[
                      aws.iam.GetPolicyDocumentStatementPrincipalArgs(
                            type="Service",
                            identifiers=["<http://backup.amazonaws.com|backup.amazonaws.com>"],
                        ),
                    ],
                    actions=["sts:AssumeRole"],
                ),
            ],
        )

        # create back up role for AWS Backup Service
        self.backup_role = aws.iam.Role(
            backup_role_name,
            assume_role_policy=self.role_policy.json,
            opts=parent_ops,
        )

        # attach AWSBackupServiceRolePolicyForBackup to backup_role
        self.policy_attachment = aws.iam.RolePolicyAttachment(
            backup_policy_attachment_name,
            policy_arn="arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup",
            role=self.backup_role.name,
            opts=parent_ops,
        )
I can also share my tests
This is from the terminal output:
Copy code
../../../.pyenv/versions/3.11.2/lib/python3.11/site-packages/pulumi_aws/iam/get_policy_document.py:462: in get_policy_document
    id=__ret__.id,
E   AttributeError: 'NoneType' object has no attribute 'id'
        __args__   = {'overrideJson': None, 'overridePolicyDocuments': None, 'policyId': None, 'sourceJson': None, ...}
        __ret__    = None
        opts       = <pulumi.invoke.InvokeOptions object at 0x1051a5d90>
        override_json = None
        override_policy_documents = None
        policy_id  = None
        source_json = None
        source_policy_documents = None
        statements = [<pulumi_aws.iam._inputs.GetPolicyDocumentStatementArgs object at 0x10510b090>]
        version    = None
I'm not sure why get_policy_document is returning a NoneType.
maybe I'm not mocking enough of my environment