What is the best practice for injecting a gitlab t...
# getting-started
a
What is the best practice for injecting a gitlab token?
This is my current code
Copy code
import pulumi
import pulumi_gitlab as gitlab
import os
from dotenv import load_dotenv

load_dotenv()

gitlab_token = os.getenv("GITLAB_TOKEN")

if not gitlab_token:
    raise ValueError(
        "GITLAB_TOKEN is not set. Please export it as an environment variable."
    )

gitlab_group = gitlab.Group(
    "example-group",
    path="example-group-path",
    name="Example Group",
    visibility_level="public",
)

gitlab_project = gitlab.Project(
    "example-project",
    name="example-project",
    path="example-project-path",
    namespace_id=gitlab_group.id,
    visibility_level="public",
    description="An example GitLab project managed by Pulumi.",
)

pulumi.export("group_web_url", gitlab_group.web_url)
pulumi.export("project_web_url", gitlab_project.web_url)
And the output:
Copy code
(venv) lmilbaum@lmilbaum-mac pulumi % pulumi up                      
Please choose a stack, or create a new one: dev
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing update (dev):
     Type                   Name            Plan       Info
 +   pulumi:pulumi:Stack    pulumi-poc-dev  create     
     └─ gitlab:index:Group  example-group              1 error

Diagnostics:
  gitlab:index:Group (example-group):
    error: 2 errors occurred:
        * 1 error occurred:
        * No GitLab token configured, either use the `token` provider argument or set it as `GITLAB_TOKEN` environment variable
    
    
        * Failed to create GitLab Client from provider configuration: The provider failed to create a new GitLab Client from the given configuration: No GitLab token configured, either use the `token` provider argument or set it as `GITLAB_TOKEN` environment variable

Resources:
    + 1 to create
d
a
Thank you for your feedback. Maybe this route is a bit complex for my current knowledge and experience with Pulumi. Hence, injected the secret with
pulumi config
command. For some unknown reason I'm hitting
Copy code
(venv) lmilbaum@lmilbaum-mac pulumi % pulumi up --stack dev                                              
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing update (dev):
     Type                     Name             Plan       
     pulumi:pulumi:Stack      pulumi-poc-dev              
 +   ├─ gitlab:index:Group    example-group    create     
 +   └─ gitlab:index:Project  example-project  create     

Outputs:
  + group_web_url  : output<string>
  + project_web_url: output<string>

Resources:
    + 2 to create
    1 unchanged

Do you want to perform this update? yes
Updating (dev):
     Type                   Name            Status                  Info
     pulumi:pulumi:Stack    pulumi-poc-dev  **failed**              1 error
 +   ├─ gitlab:index:Group  example-group   **creating failed**     1 error
     └─ gitlab:index:Group  example-group
   **failed**              1 error

Diagnostics:
  pulumi:pulumi:Stack (pulumi-poc-dev):
    error: update failed

  gitlab:index:Group (example-group):
    error: 1 error occurred:
        * POST <https://gitlab.com/api/v4/groups>: 403 {message: 403 Forbidden}

  gitlab:index:Group (example-group
):
    error:   sdk-v2/provider2.go:515: sdk.helper_schema: POST <https://gitlab.com/api/v4/groups>: 403 {message: 403 Forbidden}: provider=gitlab@8.8.0

Resources:
    1 unchanged

Duration: 2s
nm. problem solved.