https://pulumi.com logo
Title
c

creamy-monkey-35142

01/03/2023, 3:25 AM
e

echoing-dinner-19531

01/03/2023, 10:38 AM
You'd have to hit the cloudflare api directly, not via pulumi. We've looked at adding some sort of general query support for resources to each provider, but not something we support yet.
c

creamy-monkey-35142

01/03/2023, 10:42 AM
so is possible to get id from
output
, I’m thinking 2 way to do it • use id from output or Pulumi state file • create our own id list while running Pulumi with
accessGroup = cloudflare.AccessGroup(**v)
        return_id = accessGroup.id.apply(lambda a: print(f"{a}"))
        print(return_id)
and result is
11f9b35b-9174-4df8-ab2a-redacted
    d1478109-50f2-4aed-b375-redacted
    ec03461c-158e-49a1-b318-redacted
but I don’t know how to assign it as variable, tried with
return_id = accessGroup.id.apply(lambda a: a)
but it return
Calling __str__ on an Output[T] is not supported.
    To get the value of an Output[T] as an Output[str] consider:
    1. o.apply(lambda v: f"prefix{v}suffix")
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of Pulumi.
e

echoing-dinner-19531

01/03/2023, 10:59 AM
ohhh
I mean just use the accessGroup.id in that case, it's an Output<string> but you can use that in most other resource constructors, and if you need the raw value you can use it inside the apply
I thought you were asking about how to import an access group by name that pulumi didn't already know about.
c

creamy-monkey-35142

01/03/2023, 2:23 PM
Hi there, I’ve tried with
accessGroup = cloudflare.AccessGroup(**v)
        print(accessGroup.id)
        pulumi.export("group_id", accessGroup.id)
and result is
Calling __str__ on an Output[T] is not supported.
    To get the value of an Output[T] as an Output[str] consider:
    1. o.apply(lambda v: f"prefix{v}suffix")
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of Pulumi.

Outputs:
  + group_id: "5d624102-5a12-4ac4-a3ea-db0ec95df84a"
the context is I create access group from a python function and when user define access policy with group name, then I’ll get group
id
from group name, it’ll help user can define policy without find somewhere for group id
I was use 2 other function as a trick in this case
def set_grous_output(self, key, value):
        self.groups_output[key] = value

    def get_groups_output(self, key):
        if key in self.groups_output:
            return self.groups_output[key]
        else:
            return None
it’ll define group with name & id and id at this time is in memory like
[<pulumi.output.Output object at 0x103e68130>]
and input resource before create Access Policy will be
Diagnostics:
  pulumi:pulumi:Stack (pulum-redacted):
    {'application_id': <pulumi.output.Output object at 0x10a0c8dc0>, 'account_id': 'redacted', 'resource_name': 'bypass', 'name': 'bypass', 'decision': 'bypass', 'precedence': 1, 'includes': [<pulumi_cloudflare._inputs.AccessPolicyIncludeArgs object at 0x10a0a7af0>]}
but it like a trick because I need to run
cloudflare.AccessGroup
first to have list, what I expected is I can get group
id
from state file or somewhere official than write our own function
e

echoing-dinner-19531

01/03/2023, 3:01 PM
I mean you could go look in the state file (
pulumi stack export
) it's just JSON should be pretty easy to understand. But you've got the id its just wrapped in an output, but you can save that from inside the apply. Note that it has to be an output because your program runs at preview time, and at preview time when creating a new AccessGroup there is no id! You have to handle that case, Output<T> handles it for you by just not running apply when the value isn't actually available.
c

creamy-monkey-35142

01/03/2023, 3:12 PM
so is there anyway to get
pulumi stack export
result in python code? should I do it with pulumi
automation
and hope you can share me an example
e

echoing-dinner-19531

01/03/2023, 3:51 PM
There's an
export_stack
function on the workspace type in the python automation api. That gives you back an object with a
deployment: Optional[Mapping[str, Any]]
field. If you look through that mapping the id info would be in there somewhere. But again you have the id in your program you just need to access it within the Apply block.
c

creamy-monkey-35142

01/03/2023, 3:56 PM
thank, that is helped me too much and have some idea to work with it, thank you again