https://pulumi.com logo
#general
Title
# general
r

rhythmic-sunset-53997

07/14/2023, 8:59 AM
Hi, I’d like to ask about what is the best/recommended way to implement the following use case. I’m using Python. I want to create a certain GitLab CI/CD variable for a list of GitLab projects that I construct dynamically by calling the API directly (with
requests
). The GitLab API needs an authentication token that I am providing via a configuration secret:
Copy code
gitlab_config = pulumi.Config('gitlab')
gitlab_apikey = gitlab_config.require_secret('api_key')
This already is problematic, as the value of
gitlab_apikey
is an
Output[string]
. In order to use it in
requests
, I need to do everything inside an `apply()`:
Copy code
(...)

def get_projects(api_key: str):
    gl = gitlab.GitLabApi(api_key)

    projects = gl.get_projects()
    for project in projects:
        print(project.path)

gitlab_apikey.apply(get_projects)
This works OK, but now I would need to create resources (namely, the gitlab.ProjectVariable resource) and Pulumi best practice (that I read somewhere in a github issue from someone at Pulumi, so assuming it’s correct) is to not create resources in the
apply()
callback. So, what are my options here? Thank you!
4 Views