Sorry, another question. I also can't find how not...
# general
b
Sorry, another question. I also can't find how not to recreate the resource if, let's say, its name changes. To specify, I want to deliberately forbit resource recreation.
b
b
thanks @broad-helmet-79436, I will try this. But I though there was something like 'ignore_recreate' in ResourceOptions, which is available in terraform
b
ignoreChanges @better-actor-92669
;)
# Changes to the value of
prop
will not lead to updates/replacements res = MyResource("res", prop="new-value", opts=ResourceOptions(ignore_changes=["prop"]))
b
@broad-dog-22463, fantastic, thanks a lot!
Copy code
opts=ResourceOptions(
                         depends_on=[cloud_pgsql_main_1],
                         ignore_changes=['name'],
                         protect=True,
                     ),
đź‘Ť 1
b
@better-actor-92669 what name is changing?
They shouldn’t change if they are auto named...
b
@broad-dog-22463, I will explain my use case. I want to create a GCP CloudSQL Postgres Database Instance and a Read Replica for it. Since GCP doesn't fully delete your database instance for a while, the name is reserved, so I've created a workaround like this:
Copy code
def random_string(string_length=5):
    """Generate a random string of fixed length """
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for _ in range(string_length))
to generate names for Database Instances in my test project, because I am experimenting with different settings and recreate instances very often. Then I utilise it:
Copy code
MASTER_INSTANCE_NAME = config.get('psql_instance_name') or get_project() +\
                '-psql-main-1-' + random_string()

cloud_pgsql_main_1 =\
    DatabaseInstance('cloud_pgsql_main_1',
                     opts=ResourceOptions(
                         depends_on=[sql_admin_api],
                         ignore_changes=['name'],
                         protect=True,
                     ),
                     database_version='POSTGRES_11',
                     name=MASTER_INSTANCE_NAME,
b
Ah :) nice workaround eventual consistency
b
@broad-dog-22463 it seems like protect for python SDK is not working properly. When I set it to False it still says
Copy code
error: Preview failed: refusing to delete protected resource
b
Did you run
pulumi up
after setting it to false, before making a change that forces recreation?
b
yes, I think it also depends on
Copy code
ignore_changes=