https://pulumi.com logo
#general
Title
# general
g

great-sunset-355

07/23/2021, 9:45 AM
How can I copy config between different projects? I've renamed the project by exporting and importing the stack, now I'd like to also copy the config to the new project, how can I do it? I tried
Copy code
pulumi config cp --stack staging  --dest <owner>/dest-proj/staging
I get
error: [400] Message authentication failed
1
b

brave-planet-10645

07/23/2021, 9:53 AM
Do you have the correct access on the new stack? Does the new stack exist?
Also, are you actually copying it from one stack to another if you've renamed the old one?
g

great-sunset-355

07/23/2021, 10:09 AM
yes I can see both projects and their stacks in pulumi console I resolved the error by
pulumi config refresh
in old project however now the command can pass without any result
I can now that encrpyted config values depend on the directory where the
pulumi
command is run from in my current structure
Copy code
new_proj/
   old_proj/
        __main__.py
  __main__.py
commands:
Copy code
cd new_proj
pulumi config --show-secrets  # empty as expected

cd old_proj
pulumi config --show-secrets # returns values

cd ..  # back to new_proj
pulumi config --show-secrets -C old_proj  # error 400 auth failed

pulumi config refresh -C old_proj 
pulumi config --show-secrets -C old_proj  # returns values
however none of the commands above helped to resolve the issue with copying the config:
Copy code
cd new_proj

pulumi config cp --dest owner/new_proj/staging -C old_proj
also
-v 3
does not give any debug log
I seem to be confused from stack names and organisations
if I understand it correctly the naming is
owner/project/stack
however on the website there is one more box
stx/tqs-backend
is the repository - does this play any role in the naming? what would be the actual name of the project and stack inside? I have a project called
old_project
there with stack
staging
Is the fully qualified name:
owner/old_project/staging
or is it
owner/stx/tqs-backend/old_project/staging
? Or something completely different because some other projects are created directly in my namespace
Hmm in the end I managed to do it using automation api:
Copy code
from pulumi import automation as auto

owner = 'owner'

new_project_name = "new_proj"
new_stack_name = f"{new_project_name}/staging"
old_project_name = "old_proj"
old_stack_name = f"{old_project_name}/staging"
new_stack = auto.select_stack(
    stack_name=f"{owner}/{new_stack_name}", project_name=new_project_name, program=lambda: ""
)
old_stack = auto.select_stack(
    stack_name=f"{owner}/{old_stack_name}", project_name="does not matter", program=lambda: ""
)

old_stack.refresh_config()

# update project config namespace
new_config = {k.replace(f"{old_project_name}:", f"{new_project_name}:"): v for k, v in old_stack.get_all_config().items()}
new_stack.set_all_config(new_config)

# update new stack
new_stack.up()
20 Views