https://pulumi.com logo
b

better-actor-92669

01/03/2020, 10:49 AM
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

broad-helmet-79436

01/03/2020, 10:59 AM
b

better-actor-92669

01/03/2020, 11:04 AM
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

broad-dog-22463

01/03/2020, 11:10 AM
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

better-actor-92669

01/03/2020, 11:13 AM
@broad-dog-22463, fantastic, thanks a lot!
Copy code
opts=ResourceOptions(
                         depends_on=[cloud_pgsql_main_1],
                         ignore_changes=['name'],
                         protect=True,
                     ),
đź‘Ť 1
b

broad-dog-22463

01/03/2020, 11:15 AM
@better-actor-92669 what name is changing?
They shouldn’t change if they are auto named...
b

better-actor-92669

01/03/2020, 11:18 AM
@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

broad-dog-22463

01/03/2020, 11:47 AM
Ah :) nice workaround eventual consistency
b

better-actor-92669

01/03/2020, 2:20 PM
@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

broad-helmet-79436

01/03/2020, 2:29 PM
Did you run
pulumi up
after setting it to false, before making a change that forces recreation?
b

better-actor-92669

01/03/2020, 2:37 PM
yes, I think it also depends on
Copy code
ignore_changes=