pulumi / pulumi-aws-iam

A Pulumi Multi Language Component for working with AWS IAM resources.
Apache License 2.0
6 stars 5 forks source link

python: pulumi_aws_iam.EKSRole requires that the cluster exists before it can be used in a graph #3

Closed quodlibetor closed 2 years ago

quodlibetor commented 2 years ago

What happened?

(thanks for the fast fix on #1!)

There are two related issues:

Trying to automatically create dependencies by using the output of pulumi_eks.Cluster as an input to EKSRole doesn't work.

This results in a traceback:

import pulumi_eks as eks
import pulumi_aws_iam as iam

cluster = eks.Cluster("example")
iam.EKSRole(
    "app-role",
    role=iam.RoleArgs(
        name=f"app-eks-role",
        policy_arns=["something-valid"],
    ),
    cluster_service_accounts={
        cluster.name: ["default:example-app"],
    },
)
```text File "...pulumi/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 820, in update _SetStructValue(self.fields[key], value) TypeError: bad argument type for built-in operation error: an unhandled error occurred: Program exited with non-zero exit code: 1 ``` (expand for full traceback) ``` error: Program failed with an unhandled exception: error: Traceback (most recent call last): File "/Users/bwm/.asdf/installs/pulumi/3.36.0/bin/pulumi-language-python-exec", line 107, in loop.run_until_complete(coro) File "/Users/bwm/.asdf/installs/python/3.10.3/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete return future.result() File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 126, in run_in_stack await run_pulumi_func(lambda: Stack(func)) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 51, in run_pulumi_func await wait_for_rpcs() File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 110, in wait_for_rpcs raise exception File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/rpc_manager.py", line 68, in rpc_wrapper result = await rpc File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/output.py", line 98, in is_value_known return await is_known and not contains_unknowns(await future) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/output.py", line 98, in is_value_known return await is_known and not contains_unknowns(await future) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/output.py", line 98, in is_value_known return await is_known and not contains_unknowns(await future) [Previous line repeated 9 more times] File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 514, in do_register resolver = await prepare_resource(res, ty, custom, remote, props, opts, typ) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 124, in prepare_resource serialized_props = await rpc.serialize_properties( File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/rpc.py", line 189, in serialize_properties struct[translated_name] = result File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 784, in __setitem__ _SetStructValue(self.fields[key], value) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 746, in _SetStructValue struct_value.struct_value.update(value) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/google/protobuf/internal/well_known_types.py", line 820, in update _SetStructValue(self.fields[key], value) TypeError: bad argument type for built-in operation error: an unhandled error occurred: Program exited with non-zero exit code: 1 ```

Trying to explicitly set a depends_on relationship with a string literal name also fails:

import pulumi_eks as eks
import pulumi_aws_iam as iam

cluster_name = "example"
cluster = eks.Cluster(
    "example",
    name=cluster_name
)
iam.EKSRole(
    "app-role",
    role=iam.RoleArgs(
        name=f"app-eks-role",
        policy_arns=["something-valid"],
    ),
    cluster_service_accounts={
        cluster_name: ["default:example-app"],
    },
    opts=pulumi.ResourceOptions(depends_on=[cluster]),
)
```text grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNKNOWN details = "creating component: rpc error: code = Unknown desc = invocation of aws:eks/getCluster:getCluster returned an error: invoking aws:eks/getCluster:getCluster: 1 error occurred: * error reading EKS Cluster (example): couldn't find resource ``` (expand for full traceback) ```text error: Program failed with an unhandled exception: error: Traceback (most recent call last): File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 602, in do_rpc_call return monitor.RegisterResource(req) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/grpc/_channel.py", line 946, in __call__ return _end_unary_response_blocking(state, call, False, None) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNKNOWN details = "creating component: rpc error: code = Unknown desc = invocation of aws:eks/getCluster:getCluster returned an error: invoking aws:eks/getCluster:getCluster: 1 error occurred: * error reading EKS Cluster (example): couldn't find resource " debug_error_string = "{"created":"@1657814320.267821000","description":"Error received from peer ipv4:127.0.0.1:56541","file":"src/core/lib/surface/call.cc","file_line":967,"grpc_message":"creating component: rpc error: code = Unknown desc = invocation of aws:eks/getCluster:getCluster returned an error: invoking aws:eks/getCluster:getCluster: 1 error occurred:\n\t* error reading EKS Cluster (example): couldn't find resource\n\n","grpc_status":2}" > During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/bwm/.asdf/installs/pulumi/3.36.0/bin/pulumi-language-python-exec", line 107, in loop.run_until_complete(coro) File "/Users/bwm/.asdf/installs/python/3.10.3/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete return future.result() File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 126, in run_in_stack await run_pulumi_func(lambda: Stack(func)) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 51, in run_pulumi_func await wait_for_rpcs() File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/stack.py", line 110, in wait_for_rpcs raise exception File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/rpc_manager.py", line 68, in rpc_wrapper result = await rpc File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/output.py", line 98, in is_value_known return await is_known and not contains_unknowns(await future) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/output.py", line 98, in is_value_known return await is_known and not contains_unknowns(await future) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/output.py", line 98, in is_value_known return await is_known and not contains_unknowns(await future) [Previous line repeated 9 more times] File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 607, in do_register resp = await asyncio.get_event_loop().run_in_executor(None, do_rpc_call) File "/Users/bwm/.asdf/installs/python/3.10.3/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/resource.py", line 604, in do_rpc_call handle_grpc_error(exn) File "/Users/bwm/repos/whatchow/infra/pulumi/venv/lib/python3.10/site-packages/pulumi/runtime/settings.py", line 276, in handle_grpc_error raise grpc_error_to_exception(exn) Exception: creating component: rpc error: code = Unknown desc = invocation of aws:eks/getCluster:getCluster returned an error: invoking aws:eks/getCluster:getCluster: 1 error occurred: * error reading EKS Cluster (example): couldn't find resource ```

Steps to reproduce

see the two examples in "what happened"

Expected Behavior

I expected:

Actual Behavior

Pulumi crashes when trying to construct an EKSRole in the same up as the cluster it depends on.

Versions used

$ pulumi about
CLI
Version      3.36.0
Go Version   go1.17.11
Go Compiler  gc

Plugins
NAME        VERSION
aws         5.10.0
aws-iam     0.0.5
awsx        1.0.0-beta.9
docker      3.2.0
eks         0.40.0
kubernetes  3.20.0
python      unknown

Host
OS       darwin
Version  12.4
Arch     x86_64

...

Dependencies:
NAME            VERSION
pip             22.0.4
pulumi-aws-iam  0.0.5
pulumi-awsx     1.0.0b9
pulumi-eks      0.40.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).