As part of a Pulumi Python project, I need to loop over certificates stored in the Pulumi YAML config file, and pass into a function creating the certificates.
The certificates are stored in a list in the YAML file, with the values "name", "value" and "password", where "value" and "password" is Pulumi Secrets.
I am struggling on getting the secrets from the list and passing into my create_certificate function. I have done various attempts with apply and similar but struggle getting it to work.
The Pulumi YAML file looks like this:
config:
myapp-env:certificates:
- name: my-web-cert
password:
secure: xxx
value:
secure: yyy
myapp-env:certificates:
- name: second-web-cert
password:
secure: xxx
value:
secure: yyy
myapp-env:env: dev
myapp-env....
__main__.py:
def create_certificate(
name, rg_name, environment, location, password, value, tags=None, dependsOn=None
):
certificate = Certificate(
resource_name=name,
certificate_name=name,
environment_name=environment.name,
location=location,
resource_group_name=rg_name,
properties=CertificatePropertiesArgs(password=password, value=value),
tags=tags,
opts=pulumi.ResourceOptions(depends_on=dependsOn)
if dependsOn
else pulumi.ResourceOptions(),
)
return certificate
...
certificates = config.get_object("certificates")
if certificates:
for certificate in certificates:
name = certificate.get("name")
password = x
value = x
cert = create_certificate(
name=name,
rg_name=rg,
environment=managed_env,
password=password,
value=value,
tags=tags,
dependsOn=managed_env,
location=location,
)