pulumi/tests/integration
Luke Hoban 3768e5c690
Python Dynamic Providers (#2900)
Dynamic providers in Python.

This PR uses [dill](https://pypi.org/project/dill/) for code serialization, along with a customization to help ensure deterministic serialization results.

One notable limitation - which I believe is a general requirement of Python - is that any serialization of Python functions must serialize byte code, and byte code is not safely versioned across Python versions.  So any resource created with Python `3.x.y` can only be updated by exactly the same version of Python.  This is very constraining, but it's not clear there is any other option within the realm of what "dynamic providers" are as a feature.  It is plausible that we could ensure that updates which only update the serialized provider can avoid calling the dynamic provider operations, so that version updates could still be accomplished.  We can explore this separately.

```py
from pulumi import ComponentResource, export, Input, Output
from pulumi.dynamic import Resource, ResourceProvider, CreateResult, UpdateResult
from typing import Optional
from github import Github, GithubObject

auth = "<auth token>"
g = Github(auth)

class GithubLabelArgs(object):
    owner: Input[str]
    repo: Input[str]
    name: Input[str]
    color: Input[str]
    description: Optional[Input[str]]
    def __init__(self, owner, repo, name, color, description=None):
        self.owner = owner
        self.repo = repo
        self.name = name
        self.color = color
        self.description = description

class GithubLabelProvider(ResourceProvider):
    def create(self, props):
        l = g.get_user(props["owner"]).get_repo(props["repo"]).create_label(
            name=props["name"],
            color=props["color"],
            description=props.get("description", GithubObject.NotSet))
        return CreateResult(l.name, {**props, **l.raw_data}) 
    def update(self, id, _olds, props):
        l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id)
        l.edit(name=props["name"],
               color=props["color"],
               description=props.get("description", GithubObject.NotSet))
        return UpdateResult({**props, **l.raw_data})
    def delete(self, id, props):
        l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id)
        l.delete()

class GithubLabel(Resource):
    name: Output[str]
    color: Output[str]
    url: Output[str]
    description: Output[str]
    def __init__(self, name, args: GithubLabelArgs, opts = None):
        full_args = {'url':None, 'description':None, 'name':None, 'color':None, **vars(args)}
        super().__init__(GithubLabelProvider(), name, full_args, opts)

label = GithubLabel("foo", GithubLabelArgs("lukehoban", "todo", "mylabel", "d94f0b"))

export("label_color", label.color)
export("label_url", label.url)
```


Fixes https://github.com/pulumi/pulumi/issues/2902.
2019-07-19 10:18:25 -07:00
..
aliases Fix crash when there were multiple duplicate aliases to the same resource. (#2865) 2019-06-23 02:16:18 -07:00
config_basic Remove existing lock files 2018-11-12 15:33:58 -08:00
config_capture_e2e/nodejs Remove existing lock files 2018-11-12 15:33:58 -08:00
delete_before_create Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
dependency_steps Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
double_pending_delete Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
duplicate_urns Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
dynamic/python Python Dynamic Providers (#2900) 2019-07-19 10:18:25 -07:00
ee_perf Use prefered new pulumi.Config() form 2019-01-31 16:11:57 -08:00
empty Remove existing lock files 2018-11-12 15:33:58 -08:00
explicit_provider Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
get_created Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
invalid_package_json Remove existing lock files 2018-11-12 15:33:58 -08:00
partial_state Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
project_main Remove existing lock files 2018-11-12 15:33:58 -08:00
project_main_abs Fix pending delete replacement failure (#658) 2017-12-07 09:44:38 -08:00
project_main_parent Fix pending delete replacement failure (#658) 2017-12-07 09:44:38 -08:00
protect_resources Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
provider_secret_config Do not pass arguments as secrets to CheckConfig/Configure 2019-05-17 16:42:29 -07:00
query Implement listResourceOutputs in the Node.js SDK 2019-06-03 14:56:49 -07:00
read Add support for importing existing resources. (#2893) 2019-07-12 11:12:01 -07:00
recreate_resource_check Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
secret_outputs Correctly flow secretness across POJO serliazation for stack outputs 2019-06-26 15:16:07 -07:00
single_resource Suppress JSON outputs in preview correctly (#2771) 2019-05-25 12:10:38 +02:00
stack_bad_parenting Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
stack_dependencies Remove existing lock files 2018-11-12 15:33:58 -08:00
stack_outputs Remove existing lock files 2018-11-12 15:33:58 -08:00
stack_parenting Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
stack_project_name Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
stack_reference Make it possible to get a StackReference output promptly (#2824) 2019-06-17 12:25:56 -07:00
steps Consistent dependencies (#2517) 2019-03-05 20:34:51 -08:00
integration_test.go Python Dynamic Providers (#2900) 2019-07-19 10:18:25 -07:00