This message was deleted.
# python
s
This message was deleted.
p
can you paste the
create_app_role
body?
AFAIK, you cannot really convert
Output[str]
to
str
due to its lazy evaluation features. I guess, you’re trying to modify somehow the
endpoint
argument within
create_app_role
. I don’t know the whole picture but would it be a problem for you to accept
Input[str]
instead of
str
in this function and perform
apply
on it?
f
@prehistoric-activity-61023 Here is the body:
Copy code
def create_app_role(host,admin_username,admin_password,payload,role_name):
    #logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
    #logging.debug('This message should go to the log file')
    url = 'https://' + host + '/_plugins/_security/api/roles/' + role_name
    basic_creds = admin_username + ':' + admin_password
    base64_bytes = base64.standard_b64encode(basic_creds.encode('utf-8'))
    base64_message = base64_bytes.decode('utf-8')

    headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Basic ' + base64_message
    }
    http = urllib3.PoolManager()
    resp = http.request(
        "GET",
        url,
        headers=headers
    )
    #print(resp)
    if resp.status == 404:
        print('404 Role not found')
        #logging.debug('404 Role not found')
        print('Adding custom role')
        app_role_payload_bytes = json.dumps(payload).encode('ascii')
        resp = http.request(
            "PUT",
            url,
            body=app_role_payload_bytes,
            headers=headers
        )
    else:
        print('Role exists ')
p
well, if you accept
Input[str]
instead of
str
, you could do:
Copy code
url = pulumi.Output.concat('https://', host, '/_plugins/_security/api/roles/', role_name)
within that function
What actually bothers me more is that this code seems to be pretty imperative rather than declarative and IMO it’s not gonna be a good fit for pulumi (or any other declarative tool).
If I were you, I’d take a closer look a dynamic providers and try to translate the given function into a proper resource.
f
As I mentioned I am very new to pulumi, and the code was never meant to be declarative. It was simply code I'm using to understand Input / Output in pulumi. Test/POC code. The Dynamic Provider looks to be what I need. It even mentions calling REST apis. I will investigate.
p
Oh, I see. That changes a lot 🙂.
f
Thank you for pointing me in the right direction.