bulky-planet-94783
10/23/2024, 6:16 PMdef main():
"""Setup the Pulumi application environment"""
appName="simple-app"
factoryId="CL1004"
stackEnv="dev"
region="us-east-1"
vpcID="vpc-0e9250c80816d4a96"
numAZs="3"
dbType="docdb"
if appName and factoryId:
projName=factoryId+ "-" + appName
else:
return "Please provide both an application name and a factory ID."
os.environ['PULUMI_CONFIG_PASSPHRASE'] = ''
# Create working directory for the application stacks (environments)
if not os.path.exists(projName):
try:
pathlib.Path(projName).mkdir(parents=True)
work_dir=str(projName)
except FileExistsError:
"Application folder already exists."
work_dir=str(projName)
else:
work_dir=str(projName)
# Select or setup the stack
try:
stack = auto.create_or_select_stack(
stack_name=stackEnv,
project_name=projName,
program=pulumi_program,
work_dir=work_dir
)
stack.workspace.install_plugin("aws", "6.56.1")
stack.set_config("aws:region", auto.ConfigValue(value=region))
stack.set_config("aws:profile", auto.ConfigValue(value="<redacted>"))
stack.set_config("vpcID", auto.ConfigValue(value=vpcID))
stack.set_config("numAZs", auto.ConfigValue(value=numAZs))
stack.set_config("dbType", auto.ConfigValue(value=dbType))
print(f"Created new stack '{stackEnv}' for '{projName}'.")
except auto.StackAlreadyExistsError:
print(f"Stack '{stackEnv}' for '{projName}' already exists.")
except auto.RuntimeError as e:
print(f"Runtime error: {e}")
except auto.RuntimeError as e:
print(f"Runtime error: {e}")
sparse-gold-10561
10/23/2024, 6:22 PM.create_or_select_stack
sparse-gold-10561
10/23/2024, 6:23 PMbulky-planet-94783
10/23/2024, 6:24 PM.create_or_select_stack
but it appeared to be doing the same thing: always creating a new workspace and stack.bulky-planet-94783
10/23/2024, 6:36 PM.create_or_select_stack
but it's doing the same thing, creating a new workspace and stack with every execution. For reference, this is how I'm setting up the environment:
def main():
"""Setup the Pulumi application environment"""
appName="simple-app"
factoryId="CL1004"
stackEnv="dev"
region="us-east-1"
vpcID="<redacted>"
numAZs="3"
dbType="docdb"
if appName and factoryId:
projName=factoryId+ "-" + appName
else:
return "Please provide both an application name and a factory ID."
os.environ['PULUMI_CONFIG_PASSPHRASE'] = ''
# Create working directory for the application stacks
if not os.path.exists(projName):
try:
pathlib.Path(projName).mkdir(parents=True)
work_dir=str(projName)
except FileExistsError:
"Application folder already exists."
work_dir=str(projName)
else:
work_dir=str(projName)
# Select or setup the stack
try:
stack = auto.create_or_select_stack(
stack_name=stackEnv,
project_name=projName,
program=pulumi_program,
work_dir=work_dir
)
stack.workspace.install_plugin("aws", "6.56.1")
stack.set_config("aws:region", auto.ConfigValue(value=region))
stack.set_config("aws:profile", auto.ConfigValue(value="<redacted>"))
stack.set_config("vpcID", auto.ConfigValue(value=vpcID))
stack.set_config("numAZs", auto.ConfigValue(value=numAZs))
stack.set_config("dbType", auto.ConfigValue(value=dbType))
print(f"Created new stack '{stackEnv}' for '{projName}'.")
except auto.StackAlreadyExistsError:
print(f"Stack '{stackEnv}' for '{projName}' already exists.")
except auto.RuntimeError as e:
print(f"Runtime error: {e}")
except auto.RuntimeError as e:
print(f"Runtime error: {e}")
sparse-gold-10561
10/23/2024, 6:45 PMbulky-planet-94783
10/23/2024, 6:45 PMsparse-gold-10561
10/23/2024, 6:45 PMbulky-planet-94783
10/23/2024, 6:46 PMsparse-gold-10561
10/23/2024, 6:46 PMsparse-gold-10561
10/23/2024, 6:46 PMstack_name_fqdn = pulumi.automation.fully_qualified_stack_name(pulumi_org, pulumi_project, stack_name)
sparse-gold-10561
10/23/2024, 6:47 PMsparse-gold-10561
10/23/2024, 6:47 PMsparse-gold-10561
10/23/2024, 6:49 PMstack = pulumi.automation.create_or_select_stack(stack_name=stack_name_fqdn, work_dir=work_dir)
with i think the program_name.. also in your case.. otherwise, its a strange problem. I've done it both ways.. in our environment.sparse-gold-10561
10/23/2024, 6:49 PMtry:
pulumi.automation.select_stack(stack_name=stack_name_fqdn, work_dir=work_dir)
print("Found existing docker stack")
stack_exists = True
except Exception:
stack_exists = False
print("First run for docker configuration, proceeding to build...")
sparse-gold-10561
10/23/2024, 6:50 PMsparse-gold-10561
10/23/2024, 6:50 PMprint("initializing stack...")
stack = pulumi.automation.create_or_select_stack(stack_name=stack_name_fqdn, work_dir=work_dir)
print("setting up stack config...")
stack.set_config("aws:region", pulumi.automation.ConfigValue(value=region))
sparse-gold-10561
10/23/2024, 6:50 PMbulky-planet-94783
10/23/2024, 6:53 PMred-match-15116
10/24/2024, 3:15 AMbulky-planet-94783
10/24/2024, 2:36 PMdef main():
"""Setup the Pulumi application environment"""
appName="simple-app"
factoryId="CL1004"
stackEnv="dev"
region="us-east-1"
vpcID="<redacted>"
numAZs="3"
dbType="docdb"
if appName and factoryId:
projName=factoryId+ "-" + appName
else:
return "Please provide both an application name and a factory ID."
os.environ['PULUMI_CONFIG_PASSPHRASE'] = ''
# Create working directory for the application stacks (environments)
path = projName
if not os.path.exists(path):
try:
pathlib.Path(path).mkdir(parents=True)
work_dir=str(path)
except FileExistsError:
"Application folder already exists."
work_dir=str(path)
else:
work_dir=str(path)
# Setup the workspace & stack
workspace_opts = auto.LocalWorkspaceOptions(
project_settings=auto.ProjectSettings(name=projName, runtime="python"),
work_dir=work_dir
)
stack_fqdn = auto.fully_qualified_stack_name(org="organization", project=projName, stack=stackEnv)
# Select or setup the stack
try:
stack = auto.create_or_select_stack(
stack_name=stack_fqdn,
project_name=projName,
program=pulumi_program,
opts=workspace_opts
)
stack.workspace.install_plugin("aws", "6.56.1")
stack.set_config("aws:region", auto.ConfigValue(value=region))
stack.set_config("aws:profile", auto.ConfigValue(value="<redacted>"))
stack.set_config("vpcID", auto.ConfigValue(value=vpcID))
stack.set_config("numAZs", auto.ConfigValue(value=numAZs))
stack.set_config("dbType", auto.ConfigValue(value=dbType))
stack.set_config("stankEnv", auto.ConfigValue(value=stackEnv))
print("Checking for any changes made outside of IaC.")
stack.refresh(on_output=print, color="always")
except auto.StackAlreadyExistsError:
print(f"Stack '{stackEnv}' for '{projName}' already exists.")
except auto.RuntimeError as e:
print(f"Runtime error: {e}")
except auto.RuntimeError as e:
print(f"Runtime error: {e}")
red-match-15116
10/24/2024, 3:35 PM