Ejemplo n.º 1
0
def check_isolation(minimal=False):
    stack_name = f'isolation-test-{uuid.uuid4()}'

    stack = automation.create_stack(stack_name=stack_name,
                                    project_name='isolation-test',
                                    program=program)

    with pytest.raises(automation.errors.CommandError):
        stack.set_config('bad', automation.ConfigValue('1'))
        stack.up(on_output=ignore)

    if not minimal:
        stack.set_config('bad', automation.ConfigValue('0'))
        stack.up(on_output=ignore)

    destroy_res = stack.destroy()
    assert destroy_res.summary.kind == "destroy"
    assert destroy_res.summary.result == "succeeded"

    stack.workspace.remove_stack(stack_name)
Ejemplo n.º 2
0
    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')
Ejemplo n.º 3
0
def create_handler():
    """creates new sites"""
    stack_name = request.json.get('id')
    content = request.json.get('content')
    try:

        def pulumi_program():
            return create_pulumi_program(content)

        # create a new stack, generating our pulumi program on the fly from the POST body
        stack = auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=pulumi_program)
        stack.set_config("aws:region", auto.ConfigValue("us-west-2"))
        # deploy the stack, tailing the logs to stdout
        up_res = stack.up(on_output=print)
        return jsonify(id=stack_name, url=up_res.outputs['website_url'].value)
    except auto.StackAlreadyExistsError:
        return make_response(f"stack '{stack_name}' already exists", 409)
    except Exception as exn:
        return make_response(str(exn), 500)
Ejemplo n.º 4
0
def update_handler(id: str):
    stack_name = id
    content = request.data.get('content')

    try:

        def pulumi_program():
            create_pulumi_program(content)

        stack = auto.select_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=pulumi_program)
        stack.set_config("aws:region", auto.ConfigValue("us-west-2"))
        # deploy the stack, tailing the logs to stdout
        up_res = stack.up(on_output=print)
        return jsonify(id=stack_name, url=up_res.outputs["website_url"].value)
    except auto.StackNotFoundError:
        return make_response(f"stack '{stack_name}' does not exist", 404)
    except auto.ConcurrentUpdateError:
        return make_response(
            f"stack '{stack_name}' already has update in progress", 409)
    except Exception as exn:
        return make_response(str(exn), 500)
Ejemplo n.º 5
0
                                    project_name=project_name,
                                    program=pulumi_program,
                                    opts=auto.LocalWorkspaceOptions(project_settings=project_settings,
                                                                    secrets_provider=secrets_provider,
                                                                    stack_settings={"dev": stack_settings}))

print("successfully initialized stack")

# for inline programs, we must manage plugins ourselves
print("installing plugins...")
stack.workspace.install_plugin("aws", "v4.0.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...")
stack.refresh(on_output=print)
print("refresh complete")

if destroy:
    print("destroying stack...")
    stack.destroy(on_output=print)
    print("stack destroy complete")
    sys.exit()

print("updating stack...")
up_res = stack.up(on_output=print)
print(f"update summary: \n{json.dumps(up_res.summary.resource_changes, indent=4)}")
Ejemplo n.º 6
0
               check=True,
               cwd=work_dir,
               capture_output=True)
subprocess.run(
    [os.path.join("venv", "bin", "pip"), "install", "-r", "requirements.txt"],
    check=True,
    cwd=work_dir,
    capture_output=True)
print("virtual environment is ready!")

# Create our stack using a local program in the ../aws-py-voting-app 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"))
stack.set_config("voting-app:redis-password",
                 auto.ConfigValue(value="my_password", secret=True))
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()

print("updating stack...")