def test_nested_config(self): stack_name = fully_qualified_stack_name("pulumi-test", "nested_config", "dev") project_dir = test_path("data", "nested_config") stack = create_or_select_stack(stack_name, work_dir=project_dir) all_config = stack.get_all_config() outer_val = all_config["nested_config:outer"] self.assertTrue(outer_val.secret) self.assertEqual( outer_val.value, "{\"inner\":\"my_secret\",\"other\":\"something_else\"}") list_val = all_config["nested_config:myList"] self.assertFalse(list_val.secret) self.assertEqual(list_val.value, "[\"one\",\"two\",\"three\"]") outer = stack.get_config("outer") self.assertTrue(outer.secret) self.assertEqual( outer_val.value, "{\"inner\":\"my_secret\",\"other\":\"something_else\"}") arr = stack.get_config("myList") self.assertFalse(arr.secret) self.assertEqual(arr.value, "[\"one\",\"two\",\"three\"]")
def setUpClass(cls) -> None: cls.STACK_NAME = 'staging' cls.REGION_NAME = 'eu-north-1' cls.WORK_DIR = os.path.join(os.path.dirname(__file__)) cls.FILE_NAME = 'bucket.txt' cls.stack = auto.create_or_select_stack(stack_name=cls.STACK_NAME, work_dir=cls.WORK_DIR) cls.stack.set_config("aws:region", auto.ConfigValue(value=cls.REGION_NAME)) cls.stack.up(on_output=print) cls.outputs = cls.stack.outputs() cls.s3 = boto3.resource('s3')
def handler(event, context): base64_bytes = event['body'].encode('ascii') message_bytes = base64.b64decode(base64_bytes) message = message_bytes.decode('ascii') json_event = json.loads(message) bucket_name = json_event["bucket"] site_title = json_event["title"] site_body = json_event["body"] project_name = "website-builder" # We use a simple stack name here, but recommend using auto.fully_qualified_stack_name for maximum specificity. stack_name = auto.fully_qualified_stack_name("leezen", project_name, bucket_name) def pulumi_program(): create_static_website(bucket_name, site_title, site_body) # create or select a stack matching the specified name and project. # this will set up a workspace with everything necessary to run our inline program (pulumi_program) stack = auto.create_or_select_stack( stack_name=stack_name, project_name=project_name, program=pulumi_program, opts=LocalWorkspaceOptions(pulumi_home="/tmp/pulumi_home")) print("successfully initialized stack") # for inline programs, we must manage plugins ourselves print("installing plugins...") stack.workspace.install_plugin("aws", "v3.26.1") print("plugins installed") # set stack configuration specifying the AWS region to deploy print("setting up config") stack.set_config("aws:region", auto.ConfigValue(value="us-west-2")) print("config set") print("updating stack...") up_res = stack.up(on_output=print) print( f"update summary: \n{json.dumps(up_res.summary.resource_changes, indent=4)}" ) print(f"website url: {up_res.outputs['website_url'].value}") return { 'statusCode': 200, 'body': json.dumps({'url': up_res.outputs['website_url'].value}), }
import json import os from pulumi.x import automation as auto # To destroy our program, we can run python main.py destroy destroy = False args = sys.argv[1:] if len(args) > 0: if args[0] == "destroy": destroy = True stack_name = "dev" work_dir = os.path.join(os.path.dirname(__file__), "..", "fargate") # Create our stack using a local program in the ../fargate directory stack = auto.create_or_select_stack(stack_name="dev", work_dir=work_dir) print("successfully initialized stack") print("setting up config") stack.set_config("aws:region", auto.ConfigValue(value="us-west-2")) print("config set") print("refreshing stack") stack.refresh(on_output=print) print("refresh complete") if destroy: print("destroying stack...") stack.destroy(on_output=print) print("stack destroy complete") sys.exit()
# To destroy our program, we can run python main.py destroy destroy = False args = sys.argv[1:] if len(args) > 0: if args[0] == "destroy": destroy = True project_name = "inline_s3_project" # We use a simple stack name here, but recommend using auto.fully_qualified_stack_name for maximum specificity. stack_name = "dev" # stack_name = auto.fully_qualified_stack_name("myOrgOrUser", project_name, stack_name) # create or select a stack matching the specified name and project. # this will set up a workspace with everything necessary to run our inline program (pulumi_program) stack = auto.create_or_select_stack(stack_name=stack_name, project_name=project_name, program=pulumi_program) print("successfully initialized stack") # for inline programs, we must manage plugins ourselves print("installing plugins...") stack.workspace.install_plugin("aws", "v3.20.0") print("plugins installed") # set stack configuration specifying the AWS region to deploy print("setting up config") stack.set_config("aws:region", auto.ConfigValue(value="us-west-2")) print("config set") print("refreshing stack...")