[Pulumi] Use Pulumi GitLab provider TypeScript SDK to manage GitLab
Pulumi is a Modern Infrastructure as Code (IaC) to create, deploy, and manage infrastructure on any cloud using familiar programming languages and tools.
The GitLab provider for Pulumi can be used to provision any of the cloud resources available in GitLab. The GitLab provider must be configured with credentials to deploy and update resources in GitLab.
This article is about how to use Pulumi GitLab provider and TypeScript SDK to manage GitLab.
Prerequisites
-
GitLab’s DevOps platform is a single application for unparalleled collaboration, visibility, and development velocity. Learn more here Iterate faster, innovate together | GitLab - https://about.gitlab.com/!
-
GitLab account
You should have a GitLab account or Signup with Sign in · GitLab - https://gitlab.com/users/sign_in. -
GitLab Token
You should have or generate a personal access token for quick access to the GitLab API.
-
Install Pulumi and NodeJS
Pulumi
Install the Pulumi - https://www.pulumi.com/ CLI.
1 | Mac OS X |
NodeJS Language Runtime
Install Node.js - https://nodejs.org/en/.
1 | Mac OS X |
Pulumi New
First, create a directory col-pulumi-gitlab-typescript or with your prefer name.
1 | mkdir col-pulumi-gitlab-typescript |
Pulumi login into local file system.
1 | pulumi login file://. |
Pulumi new a project with TypeScript SDK.
1 | pulumi new typescript |
The above command will create some files within the current directory.
1 | tree . |
See and modify index.ts file.
1 | # main.ts |
NPM Install
Then, install pulumi-gitlab TypeScript SDK.
1 | npm install @pulumi/gitlab |
Pulumi Conf
The Pulumi GitLab Provider needs to be configured with GitLab credentials before it can be used to create resources.
Once obtained, there are two ways to communicate your authorization tokens to Pulumi:
Set the environment variable GITLAB_TOKEN:
1 | export GITLAB_TOKEN=XXXXXXXXXXXXXX |
Set them using configuration, if you prefer that they be stored alongside your Pulumi stack for easy multi-user access:
1 | pulumi config set gitlab:token XXXXXXXXXXXXXX --secret |
It will put gitlab:token and value into ./Pulumi.dev.yaml.
1 | Pulumi.dev.yaml |
Remember to pass --secret when setting gitlab:token so that it is properly encrypted. A full set of configuration parameters can be found listed on the Project README.
The GitLab provider supports several options for providing access to GitLab credentials. See the GitLab setup page pulumi/pulumi-gitlab: A Pulumi package to facilitate interacting with GitLab - https://github.com/pulumi/pulumi-gitlab/ for details.
Pulumi up
Create Repository
1 | pulumi up |
You cant visit Clodolife/demo-repo-c192cd1 - https://gitlab.com/Clodolife/demo-repo-40447f2 to see the demo-repo-40447f2 repository or with your prefer name.
Rename Repository
You can rename the repository from demo-repo-40447f2 to demo-repo or with your prefer name…
Modify index.ts file.
1 | # main.ts |
Run pulumi up.
1 | pulumi up |
You cant visit Clodolife/demo-repo - https://gitlab.com/Clodolife/demo-repo to see the demo-repo repository or with your prefer name.
Pulumi Destroy
Destroy all resources created by Pulumi.
1 | pulumi destroy |
FAQs
Missing required argument: “mirror”: all of import_url,mirror
must be specified
1 | pulumi up |
Append the missing argument importUrl
to main.ts
file.
1 | const project = new gitlab.Project("my-project", { |
See Can’t create projects without a mirror url in 4.2.0 [python] · Issue #128 · pulumi/pulumi-gitlab - https://github.com/pulumi/pulumi-gitlab/issues/128 to learn more.
References
[1] GitLab | Pulumi - https://www.pulumi.com/docs/intro/cloud-providers/gitlab/
[2] GitLab Setup | Pulumi - https://www.pulumi.com/docs/intro/cloud-providers/gitlab/setup/
[4] Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
[5] Node.js - https://nodejs.org/en/
[7] Iterate faster, innovate together | GitLab - https://about.gitlab.com/