Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auto/python] Support for remote operations #11174

Merged
merged 1 commit into from Oct 28, 2022
Merged

Conversation

justinvp
Copy link
Member

@justinvp justinvp commented Oct 27, 2022

This change adds preview support for remote operations in Python's Automation API.

Here's an example of using it:

import sys
import os

import pulumi.automation as auto


args = sys.argv[1:]
destroy = args and args[0] == "destroy"

org = "justinvp"
project_name = "aws-ts-s3-folder"
stack_name = auto.fully_qualified_stack_name(org, project_name, "devpy")

stack = auto.create_or_select_remote_stack_git_source(
    stack_name=stack_name,
    url="https://github.com/pulumi/examples.git",
    branch="refs/heads/master",
    project_path=project_name,
    opts=auto.RemoteWorkspaceOptions(
        env_vars={
            "AWS_REGION":            "us-west-2",
            "AWS_ACCESS_KEY_ID":     os.environ["AWS_ACCESS_KEY_ID"],
            "AWS_SECRET_ACCESS_KEY": auto.Secret(os.environ["AWS_SECRET_ACCESS_KEY"]),
            "AWS_SESSION_TOKEN":     auto.Secret(os.environ["AWS_SESSION_TOKEN"]),
        },
    ),
)

if destroy:
    stack.destroy(on_output=print)
    print("Stack successfully destroyed")
    sys.exit()

up_res = stack.up(on_output=print)
print(f"Update succeeded!")
print(f"url: {up_res.outputs['websiteUrl'].value}")

I will add sanity tests subsequently.

@justinvp justinvp requested a review from a team October 27, 2022 21:36
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Oct 27, 2022

Changelog

[uncommitted] (2022-10-28)

Features

  • [auto/python] Support for remote operations
    #11174

summary = self.info(show_secrets)
# If it's a remote workspace, explicitly set show_secrets to False to prevent attempting to
# load the project file.
summary = self.info(show_secrets and not self._is_remote)
assert summary is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't part of the PR, but should we really have asserts in production code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we are asserting on our own logic (not user input), I think its fine. A Exception is better than misunderstanding what is going on and potentially doing the wrong thing.

@justinvp
Copy link
Member Author

bors merge

@bors
Copy link
Contributor

bors bot commented Oct 28, 2022

Build succeeded:

@bors bors bot merged commit bbde400 into master Oct 28, 2022
@pulumi-bot pulumi-bot deleted the justin/remote_python branch October 28, 2022 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants