https://pulumi.com logo
#python
Title
# python
h

hundreds-nightfall-82143

03/26/2024, 7:49 PM
I have a dynamic resource and I'm getting the following error when trying to create an instance of it:
error: Exception calling application: There is no current event loop in thread 'ThreadPoolExecutor-0_0'.
Copy code
from pulumi import Output, ResourceOptions
from pulumi.dynamic import (
    Resource,
    ResourceProvider,
    CreateResult,
    UpdateResult,
)
from pulumi_aws import secretsmanager
import json


class DatabaseSecretProvider(ResourceProvider):
    def create(self, props):
        name = props.get("name")
        secret = secretsmanager.Secret(
            resource_name=name, description="Database credentials"
        )

        secret_version = secretsmanager.SecretVersion(
            resource_name=name,
            secret_id=secret.id,
            secret_string=json.dumps(
                {
                    "username": props.get("username"),
                    "password": secretsmanager.get_random_password(
                        password_length=30, exclude_punctuation=True
                    ).random_password,
                }
            ),
        )

        return CreateResult(
            id_="12345",
            outs={"arn": secret_version.arn},
        )

    def update(self, id, olds, news):
        self.secret_version = secretsmanager.SecretVersion(
            resource_name=news["name"],
            secret_id=id,
            secret_string=json.dumps(
                {
                    "username": news["username"],
                    "password": secretsmanager.get_random_password(
                        password_length=30, exclude_punctuation=True
                    ).random_password,
                }
            ),
        )

        return UpdateResult(outs={"arn": self.secret_version.arn})

    def delete(self, id, props):
        secretsmanager.Secret(id=id).delete()
        return None


class DatabaseSecret(Resource):
    arn: Output[str]

    def __init__(self, name, username, opts=None):

        if opts is None:
            opts = ResourceOptions()

        props = {"arn": None, "name": name, "username": username}
        super().__init__(DatabaseSecretProvider(), name, props, opts)
I'm not sure how to fix this.... please help.
h

hundreds-gpu-71155

03/26/2024, 8:59 PM
are you just wrapping existing resources? I think you want a Component Resource for that, instead of Resource + Provider
it looks like you're making resources inside the provider, which i'm pretty sure is a no-no
h

hundreds-nightfall-82143

03/27/2024, 9:19 PM
Yep, I've figured that out at this point. Thank you for the reply.
Now I'm facing another issue, might post here as it's even more opaque than this one 🙂