Hi I’m following <https://www.pulumi.com/blog/auto...
# python
a
Hi I’m following https://www.pulumi.com/blog/automatically-enforcing-aws-resource-tagging-policies/#automatically-applying-tags to try auto tagging. I’m getting this error when I run the code
Copy code
error: Program failed with an unhandled exception:
    Traceback (most recent call last):
      File "/Users/vincent/workspace/sre/platform-vpc-install/__main__.py", line 5, in <module>
        from autotag import register_auto_tags
    ModuleNotFoundError: No module named 'autotag'
Am I missing a pip install of a package? The doc doesn’t say to pip install anything…
b
that error means its getting an error trying to import the function 'register_auto_tags' from the file 'autotag.py' in the same folder (containing the code for that function from that guide)...
a
So am I supposed to put the 2 functions from the first block of code (
register_auto_tags
and
auto_tag
in a file called
autotag
?
b
yeah,
autotag.py
a
In my IDE, VSCode, it’s complaining about unable to import. OK, will try…
b
i might be slightly off, but thats the gist of it. you might need an
__init__.py
somewhere
a
And what about the line
Copy code
from taggable import is_taggable
Where is that being imported from?
b
probably the same... you can also just copy those functions all into the
__main__.py
file you are using and get rid of the imports
the imports are just the authors way of breaking up the program somewhat (but its not that clear from the guide)
a
hm okay, will try. Feels like I’m and the doc is missing a pip install of something…
all the code is there, you can see how its organized
a
Thank you!
b
fun fact, that code repo was created by the CEO of Pulumi
a
Cool!, looks like it only requires pulumi and pulumi-aws 🤞
Does auto-tag require a policy as well? I was under the impression that it’s separate, where you can enforce a policy OR use auto-tag
b
not sure what you mean, i dont think so
a
I see a
policy-config.json
which lead me to think auto-tagging requires a policy enforcement.
b
ah, i see. no, the guide is showing first how to setup policy checks on tags (which is an optional feature) using the CrossGuard policy engine. The second part (in python), which you are working on, is an example of using a stack transform to apply tags to resources in the stack automatically (thus satisfying the policy check on tagging).
a
Another question - I see
taggable.py
has not been updated in 4 years. Is there an updated list of taggable_resource_types?
b
no, its just an example and not definitive
im not even sure how valid that still is-
a
Is there an updated list? or a pip package available?
OK, thank you. Appreciate all the help and tips!
b
another thing you can try, which might be way easier is to set the default tags on the provider- let me find an example in python
a
Thank you. I have a question about providers. Should I ask in a different thread?
b
i can try to answer (I work at pulumi)
a
This last example looks to be a pretty nice way to do it.
Ah I see. I’ve been trying to figure out how to query for a provider. I tried to query for a provider and it errors out. I tried to use a try/catch but it doesn’t raise an exception, the program just errors… I haven’t been able to figure out how to do it properly…
The provider is not a dynamic resource and after first run I see it get created.
The provider is in a different stack as well.
I’ve been trying to use this
Copy code
aws.Provider().get_provider(<created-provider-name>)
I don’t think this is the correct usage to query for a create provider.
b
usually i create a new provider like in that AI example and pass it along to each resource, when overriding the default-
a
My particular use case is configuring bucket replication. I have to create a bucket using 2 providers in a stack. The next stack I’m trying to use the same providers created from previous to configure replication.
In the second stack, if I try to create new providers, it complains that the providers exist and I don’t know how to query for existing resources.
b
i'd probably need to see a code example
a
Stack 1 I have 2 regions which execute
Copy code
aws.s3.BucketV2(
            resource_name=self.get_name(),
            args=self.get_bucket_args(),
            opts=pulumi.ResourceOptions(provider=aws.Provider(
            f"{self.__name}-{region}", region=region))))
here the Provider also gets created.
Now a bucket has been created in each region and a provider has been created per bucket ( not the best resuse, trying to get a hang of the ropes here) at the end of executing I see the buckets got created and the providers
Now in stack 2 I’m trying to use the providers, which were created in stack 1 to configure replication, Is that possible?
b
stacks are just instantiations of a pulumi program (for example, dev or prod), do you have 2 separate programs?
a
Essentially, I have the first stack which creates the buckets, and it’s state file. Then the second stack which I’m trying to configure bucket replication with it’s own state file.
b
then there really shouldn't be any interaction between the providers... provider is just a runtime thing that allows a resource to communicate with the underlying API
a
But if I try to create another provider with the same name in stack 1 it says the resource already exists.
b
are you sure its the provider and not the resource?
a
Maybe I should try to use a dynamic provider
I’m pretty sure, will have to put some code in to check again… I removed it since I haven’t figured out how to use it yet and was going to come back to it.
b
i see you are using
self.get_name()
maybe its just a naming collision on your resources
a
I’ll give it a shot again, and come back to the thread. Thank you for your time!
b
no problem, good luck