https://pulumi.com logo
Docs
Join the conversationJoin Slack
Channels
announcements
automation-api
aws
azure
blog-posts
built-with-pulumi
cloudengineering
cloudengineering-support
content-share
contribex
contribute
docs
dotnet
finops
general
getting-started
gitlab
golang
google-cloud
hackathon-03-19-2020
hacktoberfest
install
java
jobs
kubernetes
learn-pulumi-events
linen
localstack
multi-language-hackathon
office-hours
oracle-cloud-infrastructure
plugin-framework
pulumi-cdk
pulumi-crosscode
pulumi-deployments
pulumi-kubernetes-operator
pulumi-service
pulumiverse
python
registry
status
testingtesting123
testingtesting321
typescript
welcome
workshops
yaml
Powered by Linen
python
  • s

    steep-alligator-79173

    07/02/2020, 8:10 AM
    Im trying to write some python unittest for the infra. I have this snippet that read config from stack yaml :
    Get instance stack config
    config_instance = pulumi.Config("instance")
    config_instance = pulumi.Config("instance")
    When I try to run tests I get:
    ERROR: test_core_stack (unittest.loader._FailedTest)
    ----------------------------------------------------------------------
    ImportError: Failed to import test module: test_core_stack
    Traceback (most recent call last):
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
        module = self._get_module_from_name(name)
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
        __import__(name)
      File "/Users/pawelmadon/git/a4b/poc/qx-pulumi/core-stack/test_core_stack.py", line 13, in <module>
        import core_stack
      File "/Users/pawelmadon/git/a4b/poc/qx-pulumi/core-stack/core_stack.py", line 54, in <module>
        instance_type=config_instance.require('bastion_size'),
      File "/Users/pawelmadon/git/a4b/poc/qx-pulumi/core-stack/venv/lib/python3.7/site-packages/pulumi/config.py", line 214, in require
        raise ConfigMissingError(self.full_key(key))
    pulumi.config.ConfigMissingError: Missing required configuration variable 'instance:bastion_size'
        please set a value using the command `pulumi config set instance:bastion_size <value>`
    
    
    ----------------------------------------------------------------------
    Ran 1 test in 0.000s
    
    FAILED (errors=1)
    (venv)
    How I can import configuration to tests ?
    g
    • 2
    • 2
  • s

    stocky-lion-56153

    07/02/2020, 10:19 AM
    I guess you’d need to make a temporary stack for testing and configure it - use
    pulumi stack select --create <stack name>
  • s

    steep-alligator-79173

    07/02/2020, 8:23 PM
    I managed to fix stack variables but now Im hitting another problem. I pulling up az list with function:
    # Get az's for region
    azs = aws.get_availability_zones(state="available")
    Now when I try to run test :
    File "/Users/unittests/infra.py", line 79, in <module>
        for num, az in enumerate(azs.zone_ids):
    TypeError: 'NoneType' object is not iterable
    in Pulumi documentation i found:
    call(token: string, args: any, provider?: undefined | string): Record<string, any>
    call mocks provider-implemented function calls (e.g. aws.get_availability_zones).
    But I have no idea how I can mock this call. For any code snippet I would be grateful
    f
    • 2
    • 4
  • r

    rhythmic-napkin-82334

    07/04/2020, 6:16 PM
    Dear Pythonistas and Pulumis, I almost already started with terraform, when I noticed pulumi. Looking forward to testing IaC in Python using pulumi! I am currently trying to deploy some simple infrastructure based on the tutorials, but the NGINX on AWS ECS Fargate using Python tutorial seems to lack the link to the repository 🤔 Ah, I just understood, that the hyperlink is shown further above. I created this Pull Request as a suggestion of how to make the tutorials even more clear. 🙂
  • f

    flat-australia-79845

    07/06/2020, 1:39 PM
    Hi there. I have been working with Serverless and lambda functions in Python for a while, one thing I usually do is filter out the tests folders and
    __pycache__
    folders from the artifacts that I push to the cloud. Today I made this work in Pulumi with:
    from fnmatch import fnmatch
    from typing import Dict, Iterable, Union
    from pathlib import Path
    
    from pulumi.asset import Asset, Archive, AssetArchive, FileArchive, FileAsset
    
    
    def filter_file_archive(
        path: str, archive: FileArchive, exclude_patterns: Iterable[str] = None
    ) -> Dict[str, FileAsset]:
        if not exclude_patterns:
            exclude_patterns = []
    
        file_iterator = Path(archive.path).rglob('*')
        asset_root = Path(path)
        assets = {
            str(asset_root / file.relative_to(archive.path)): FileAsset(str(file))
            for file in file_iterator if not any({fnmatch(file, pattern) for pattern in exclude_patterns})
        }
        return assets
    
    
    class CodeAsset(AssetArchive):
    
        def __init__(self, assets: Dict[str, Union[Asset, Archive]], exclude_patterns: Iterable[str] = None):
            assets = self._filter_assets(assets, exclude_patterns)
            super().__init__(assets=assets)
    
        def _filter_assets(
            self, assets: Dict[str, Union[Asset, Archive]], exclude_patterns: Iterable[str] = None
        ) -> Dict[str, Union[Asset, Archive]]:
            filtered_assets: Dict[str, Union[Asset, Archive]] = {}
            for path, asset in assets.items():
                if isinstance(asset, FileArchive):
                    filtered_assets.update(filter_file_archive(path, asset, exclude_patterns))
                else:
                    filtered_assets[path] = asset
            return filtered_assets
    then I use it this way:
    archive = gcp.storage.BucketObject(
        f'{function_name}-cloudfunction.zip',
        bucket=bucket.name,
        source=CodeAsset({
            '.': pulumi.asset.FileArchive(str(source_folder / 'pairbot')),
            'lib': pulumi.asset.FileArchive(str(source_folder / 'lib')),
        }, exclude_patterns={'**/__pycache__*', '**/tests*'}),
    )
    b
    • 2
    • 4
  • s

    swift-lunch-74411

    07/07/2020, 2:41 PM
    Hi there,
  • s

    swift-lunch-74411

    07/07/2020, 3:00 PM
    We are trying to develop policies and test them locally before pushing them to the Pulumi backend. We have followed the documentation and the samples from Pulumi but when we run the Pulumi preview or up with --pulumi-policies <folder-path> it does nothing. Using the wrong path cause an exception that shows it is considering the folder as policy. Also the log (-v) doesn't show anything related to this
    g
    • 2
    • 5
  • b

    bland-lamp-16797

    07/09/2020, 3:10 PM
    hmmm we don't have a example how to use gcp cloud build in python? I could not find it in examples....
  • c

    clever-plumber-29709

    07/09/2020, 8:13 PM
    Has anyone used pulumi along pipenv/poetry or other similar tools? i'm curious about if there is one that suits it more, and also about the best path to distribute pulumi custom components for other projects
    m
    s
    s
    • 4
    • 3
  • a

    astonishing-quill-88807

    07/10/2020, 5:06 PM
    I'm using it with Poetry currently. Code is visible at https://github.com/mitodl/ol-infrastructure
  • a

    astonishing-quill-88807

    07/10/2020, 5:06 PM
    Still early days
  • c

    cold-minister-39214

    07/10/2020, 5:10 PM
    I'm struggling to figure out how to do an import. I feel like I'm missing something obvious, but I keep getting this:
    Diagnostics:
      ...
      digitalocean:index:DnsRecord (a):
        error: Preview failed: refreshing urn:pulumi:devjs::do-pulumi-node::digitalocean:index/dnsRecord:DnsRecord::a: domain is invalid because cannot be an empty string
    I've confirmed that the ids used for import_ are correct with the digital ocean API. If I comment out the DnsRecord, I can import the domain with no problems. Any insight would be appreciated.
    Untitled.py
  • b

    billowy-laptop-45963

    07/10/2020, 5:16 PM
    I'm getting mypy errors for the following
    return pulumi.Output.all(bucket.bucket, obj.key).apply(
        lambda args: f"<https://s3.amazonaws.com/{args[0]}/{args[1]}>"
    )
    mypy states:
    Argument 1 to "all" of "Output" has incompatible type "Output[str]"; expected "Union[<nothing>, Awaitable[<nothing>], Output[<nothing>]]"
    Argument 2 to "all" of "Output" has incompatible type "Output[str]"; expected "Union[<nothing>, Awaitable[<nothing>], Output[<nothing>]]"
    Anyone see this before?
    c
    • 2
    • 1
  • s

    stocky-lion-56153

    07/11/2020, 12:42 PM
    Hi, has anyone got any advice on how to import modules from my
    __main__.py
    please? I have this pulumi.yaml
    name: cli
    main: infra/
    runtime:
      name: python
      options:
        virtualenv: ../venv
    description: Flexiclock CLI
    And these files
    tree infra/
    infra/
    ├── __init__.py
    ├── __main__.py
    └── s3.py
  • s

    stocky-lion-56153

    07/11/2020, 12:43 PM
    If I have
    from . import s3
    in
    __main___.py
    I get an error
    ImportError: attempted relative import with no known parent package
    b
    • 2
    • 5
  • s

    salmon-gold-74709

    07/13/2020, 7:41 AM
    Hi - thinking about Pulumi for Kubernetes and multi-cloud (AWS, GCP and Azure ultimately) - wondering how complete the Python support is
    s
    g
    r
    • 4
    • 8
  • q

    quick-cricket-80200

    07/13/2020, 10:26 PM
    Hi, How do I get the log group name as string in this sample code. Not a python expert. Appreciate your help.
    log_group = aws.cloudwatch.LogGroup("/ecs/log-group")
    
    json = json.dumps([
        {
    		"name": "app",
    		"image": "image",
    		"portMappings": [{
    			"containerPort": 8080,
    			"hostPort": 8080,
    			"protocol": "tcp"
    		}],
    		"logConfiguration": {
    	        "logDriver": "awslogs",
    	        "options": {
    	          "awslogs-group": log_group.name,
    	          "awslogs-region": "us-east-1",
    	          "awslogs-stream-prefix": "ecs"
    	        }
            }
    	}
    	]
    )
    I am getting
    TypeError: Object of type Output is not JSON serializable
  • s

    sparse-state-34229

    07/13/2020, 10:39 PM
    use
    Output.apply
    b
    • 2
    • 1
  • g

    gray-jewelry-3360

    07/20/2020, 8:07 PM
    Hi Team, I'm having issues while pulumi up with the auto generated requirements.txt file, can you please provide solution for this: pulumi😛ulumi:Stack (Pulumi-latest-dev):     error: an unhandled error occurred: Program exited with non-zero exit code: 3221225781 Installing dependencies... error: installing dependencies via `pip install -r requirements.txt`: exit status 3221225781
    r
    • 2
    • 3
  • b

    better-actor-92669

    07/24/2020, 8:31 AM
    Hello Guys! I've encountered an issue with
    pulumi-postgresql
    module that should have been fixed already. Can someone from Pulumi Team take a look please?
    pulumi==2.7.1
    pulumi-gcp==3.15.0
    pulumi-kubernetes==2.4.0
    pulumi-postgresql==2.2.2
    pulumi-random==2.2.0
    https://github.com/pulumi/pulumi-postgresql/issues/60
    m
    b
    • 3
    • 5
  • b

    brave-oyster-92747

    07/24/2020, 3:58 PM
    Hi guys, I would like to use Pulumi to spin up an ec2 with ASG. If anyone had worked on it can you share your project? I will use it as a reference for my requirement.
  • b

    better-actor-92669

    07/27/2020, 2:30 PM
    hey guys. how to avoid the creation of the new python venv, using
    pulumi new
    if I already have it? https://www.pulumi.com/docs/reference/cli/pulumi_new/
    -g, --generate-only             Generate the project only; do not create a stack, save config, or install dependencies
    I need to create a stack, save config, I just need not to create the venv automatically
    g
    • 2
    • 2
  • b

    bright-policeman-55860

    08/01/2020, 1:24 AM
    Hi, has anyone ever been successful in running a system command that needs an Output? Whenever I try, either with a concatenate or an apply, it just exhausts all the memory from my system.
  • b

    bright-policeman-55860

    08/01/2020, 1:29 AM
    Just this is enough to make it break:
    subprocess.run(pulumi.Output.concat("whoami"))
  • b

    bright-policeman-55860

    08/02/2020, 12:43 PM
    Does anyone have an example of a CustomResource in Python?
    w
    • 2
    • 1
  • d

    damp-elephant-82829

    08/05/2020, 3:24 PM
    How do you wait for an awaitable resource in python?
    b
    • 2
    • 1
  • p

    proud-queen-14294

    08/06/2020, 6:18 PM
    Hi all, I'm using python on AWS. I'm having some issues with
    directoryservice.Directory
    If I copy and paste the python example here I've made MINOR adjustments, but the issue still remains. I get the following error:
    Diagnostics:
      aws:directoryservice:Directory (main):
        error: InvalidParameterException: Invalid directory name. The directory name must be between 2 and 64 characters, and can only contain alphanumeric characters, periods (.). or minus signs (-). Also, the directory name must begin and end with an alphanumeric character. : RequestId: 362da74b-62dc-4116-8785-e65cbacb52c3
        {
          RespMetadata: {
            StatusCode: 400,
            RequestID: "362da74b-62dc-4116-8785-e65cbacb52c3"
          },
          Message_: "Invalid directory name. The directory name must be between 2 and 64 characters, and can only contain alphanumeric characters, periods (.). or minus signs (-). Also, the directory name must begin and end with an alphanumeric character. : RequestId: 362da74b-62dc-4116-8785-e65cbacb52c3",
          RequestId: "362da74b-62dc-4116-8785-e65cbacb52c3"
        }
     
      pulumi:pulumi:Stack (training_workspaces-dev):
        error: update failed
    I've tried overwriting the name to avoid the generated hex code being added by using the
    name
    parameter of
    Directory
    , but it just gives the same error. I find it odd that this is happening with example code from the docs. Any ideas? Full code added as snippet
    full_code_py.py
    l
    • 2
    • 7
  • w

    witty-ice-69000

    08/08/2020, 2:10 PM
    I'm new to Pulumi and currently a bit confused about how
    pulumi --cwd <some dir>
    is supposed to work. I wanted to do something like this:
    project root
    |_ __main__.py
    |_ bootstrap
       |_ __main__.py
       |_ core_deployment.py
       |_ __init__.py
    The bootstrap package has it's own
    __main__
    file to establish the basic user, group and role for deployments and a privileged user must initially run
    pulumi --cwd bootstrap up
    . Then for all other deployments, provided bootstrap doesn't need to change, then "regular" users can run
    pulumi up
    and because the root
    __main__
    always includes the bootstrap deployment, the state for the stack is always aligned and works just fine provided the regular user doesn't need to destroy the bootstrap state, and then a privileged user is needed again. BUT using
    --cwd
    results in the root
    __main__
    being called regardless (the bootstrap
    __main__
    is ignored). Even using
    cd bootstrap; pulumi up
    still results in root
    __main__
    being called. What am I missing here?
  • e

    enough-ambulance-2841

    08/10/2020, 4:00 PM
    👋 hi all ... I'm trying to use
    aws.iam.get_policy_document
    where I use the S3 bucket ARN in the policy, but it's simply not working (I think Pulumi doesn't know the dependency graph here). What is the best practice here? The docs lack examples that fit my use case ... My example: https://github.com/iserko/pulumi-test/blob/master/__main__.py#L33-L50
    • 1
    • 1
  • p

    proud-queen-14294

    08/11/2020, 11:26 PM
    Is there any way to create a user for a workspace directory for AWS? At the moment I get
    aws:workspaces:Workspace example creating error: workspace creation failed: The specified user could not be found in the directory.
    when I specify the
    user_name
    parameter, because the user doesn't exist, but I find no parameters in the directory or workspace interfaces that allow user creation. EDIT: It appears it's part of the EC2 instance, very confused. The Workspaces GUI allows you to add users but I want to do that programatically EDIT 2: Nevermind it seems it's a limitation of the AWS API, which seems silly in my opinion.. https://stackoverflow.com/questions/56995571/create-a-user-on-aws-workspaces-with-api
Powered by Linen
Title
p

proud-queen-14294

08/11/2020, 11:26 PM
Is there any way to create a user for a workspace directory for AWS? At the moment I get
aws:workspaces:Workspace example creating error: workspace creation failed: The specified user could not be found in the directory.
when I specify the
user_name
parameter, because the user doesn't exist, but I find no parameters in the directory or workspace interfaces that allow user creation. EDIT: It appears it's part of the EC2 instance, very confused. The Workspaces GUI allows you to add users but I want to do that programatically EDIT 2: Nevermind it seems it's a limitation of the AWS API, which seems silly in my opinion.. https://stackoverflow.com/questions/56995571/create-a-user-on-aws-workspaces-with-api
View count: 1