fast-spoon-69536
03/14/2022, 5:45 PMesa.create_app_role(example.endpoint.apply(lambda endpoint: f"{endpoint}"),admin_username,admin_password,app_role_payload,role_name)
_The create_app_role function takes the following inputs._
endpoint - the endpoint is only available after the previous resource is deployed.
_admin_username - username to log into the endpoint_
_admin_password - admin password_
_app_role_payload - a dictionary / REST payload_
_role_name - name of the role to create_
The basics of what I'm trying to do is.
1. deploy aws opensearch
2. call the opensearch internal API to create roles and users after it is deployed.
endpoint needs to be a str, but it is a Output<str>. How can I get it to be a str? Or is there a better approach ?
TypeError: can only concatenate str (not "Output") to str
prehistoric-activity-61023
03/14/2022, 5:48 PMcreate_app_role
body?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?fast-spoon-69536
03/14/2022, 7:18 PMdef 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 ')
prehistoric-activity-61023
03/14/2022, 7:51 PMInput[str]
instead of str
, you could do:
url = pulumi.Output.concat('https://', host, '/_plugins/_security/api/roles/', role_name)
within that functionfast-spoon-69536
03/15/2022, 6:18 PMprehistoric-activity-61023
03/15/2022, 6:35 PMfast-spoon-69536
03/16/2022, 12:05 PM