Cluster Agent Token
The gitlab.ClusterAgentToken
resource allows to manage the lifecycle of a token for a GitLab Agent for Kubernetes.
Requires at least maintainer permissions on the project. Requires at least GitLab 15.0 Upstream API: GitLab REST API docs
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as gitlab from "@pulumi/gitlab";
import * as helm from "@pulumi/helm";
// Create token for an agent
const example = new gitlab.ClusterAgentToken("example", {
project: "12345",
agentId: 42,
description: "some token",
});
const thisProject = gitlab.getProject({
pathWithNamespace: "my-org/example",
});
const thisClusterAgent = new gitlab.ClusterAgent("thisClusterAgent", {project: thisProject.then(thisProject => thisProject.id)});
const thisClusterAgentToken = new gitlab.ClusterAgentToken("thisClusterAgentToken", {
project: thisProject.then(thisProject => thisProject.id),
agentId: thisClusterAgent.agentId,
description: "Token for the my-agent used with `gitlab-agent` Helm Chart",
});
const gitlabAgent = new helm.index.Helm_release("gitlabAgent", {
name: "gitlab-agent",
namespace: "gitlab-agent",
createNamespace: true,
repository: "https://charts.gitlab.io",
chart: "gitlab-agent",
version: "1.2.0",
set: [{
name: "config.token",
value: thisClusterAgentToken.token,
}],
});
Content copied to clipboard
import pulumi
import pulumi_gitlab as gitlab
import pulumi_helm as helm
# Create token for an agent
example = gitlab.ClusterAgentToken("example",
project="12345",
agent_id=42,
description="some token")
this_project = gitlab.get_project(path_with_namespace="my-org/example")
this_cluster_agent = gitlab.ClusterAgent("thisClusterAgent", project=this_project.id)
this_cluster_agent_token = gitlab.ClusterAgentToken("thisClusterAgentToken",
project=this_project.id,
agent_id=this_cluster_agent.agent_id,
description="Token for the my-agent used with `gitlab-agent` Helm Chart")
gitlab_agent = helm.index.Helm_release("gitlabAgent",
name=gitlab-agent,
namespace=gitlab-agent,
create_namespace=True,
repository=https://charts.gitlab.io,
chart=gitlab-agent,
version=1.2.0,
set=[{
name: config.token,
value: this_cluster_agent_token.token,
}])
Content copied to clipboard
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using GitLab = Pulumi.GitLab;
using Helm = Pulumi.Helm;
return await Deployment.RunAsync(() =>
{
// Create token for an agent
var example = new GitLab.ClusterAgentToken("example", new()
{
Project = "12345",
AgentId = 42,
Description = "some token",
});
var thisProject = GitLab.GetProject.Invoke(new()
{
PathWithNamespace = "my-org/example",
});
var thisClusterAgent = new GitLab.ClusterAgent("thisClusterAgent", new()
{
Project = thisProject.Apply(getProjectResult => getProjectResult.Id),
});
var thisClusterAgentToken = new GitLab.ClusterAgentToken("thisClusterAgentToken", new()
{
Project = thisProject.Apply(getProjectResult => getProjectResult.Id),
AgentId = thisClusterAgent.AgentId,
Description = "Token for the my-agent used with `gitlab-agent` Helm Chart",
});
var gitlabAgent = new Helm.Index.Helm_release("gitlabAgent", new()
{
Name = "gitlab-agent",
Namespace = "gitlab-agent",
CreateNamespace = true,
Repository = "https://charts.gitlab.io",
Chart = "gitlab-agent",
Version = "1.2.0",
Set = new[]
{
{
{ "name", "config.token" },
{ "value", thisClusterAgentToken.Token },
},
},
});
});
Content copied to clipboard
package main
import (
"github.com/pulumi/pulumi-gitlab/sdk/v6/go/gitlab"
"github.com/pulumi/pulumi-helm/sdk/v1/go/helm"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create token for an agent
_, err := gitlab.NewClusterAgentToken(ctx, "example", &gitlab.ClusterAgentTokenArgs{
Project: pulumi.String("12345"),
AgentId: pulumi.Int(42),
Description: pulumi.String("some token"),
})
if err != nil {
return err
}
thisProject, err := gitlab.LookupProject(ctx, &gitlab.LookupProjectArgs{
PathWithNamespace: pulumi.StringRef("my-org/example"),
}, nil)
if err != nil {
return err
}
thisClusterAgent, err := gitlab.NewClusterAgent(ctx, "thisClusterAgent", &gitlab.ClusterAgentArgs{
Project: pulumi.String(thisProject.Id),
})
if err != nil {
return err
}
thisClusterAgentToken, err := gitlab.NewClusterAgentToken(ctx, "thisClusterAgentToken", &gitlab.ClusterAgentTokenArgs{
Project: pulumi.String(thisProject.Id),
AgentId: thisClusterAgent.AgentId,
Description: pulumi.String("Token for the my-agent used with `gitlab-agent` Helm Chart"),
})
if err != nil {
return err
}
_, err = index.NewHelm_release(ctx, "gitlabAgent", &index.Helm_releaseArgs{
Name: "gitlab-agent",
Namespace: "gitlab-agent",
CreateNamespace: true,
Repository: "https://charts.gitlab.io",
Chart: "gitlab-agent",
Version: "1.2.0",
Set: []map[string]interface{}{
map[string]interface{}{
"name": "config.token",
"value": thisClusterAgentToken.Token,
},
},
})
if err != nil {
return err
}
return nil
})
}
Content copied to clipboard
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gitlab.ClusterAgentToken;
import com.pulumi.gitlab.ClusterAgentTokenArgs;
import com.pulumi.gitlab.GitlabFunctions;
import com.pulumi.gitlab.inputs.GetProjectArgs;
import com.pulumi.gitlab.ClusterAgent;
import com.pulumi.gitlab.ClusterAgentArgs;
import com.pulumi.helm.helm_release;
import com.pulumi.helm.Helm_releaseArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
// Create token for an agent
var example = new ClusterAgentToken("example", ClusterAgentTokenArgs.builder()
.project("12345")
.agentId(42)
.description("some token")
.build());
final var thisProject = GitlabFunctions.getProject(GetProjectArgs.builder()
.pathWithNamespace("my-org/example")
.build());
var thisClusterAgent = new ClusterAgent("thisClusterAgent", ClusterAgentArgs.builder()
.project(thisProject.applyValue(getProjectResult -> getProjectResult.id()))
.build());
var thisClusterAgentToken = new ClusterAgentToken("thisClusterAgentToken", ClusterAgentTokenArgs.builder()
.project(thisProject.applyValue(getProjectResult -> getProjectResult.id()))
.agentId(thisClusterAgent.agentId())
.description("Token for the my-agent used with `gitlab-agent` Helm Chart")
.build());
var gitlabAgent = new Helm_release("gitlabAgent", Helm_releaseArgs.builder()
.name("gitlab-agent")
.namespace("gitlab-agent")
.createNamespace(true)
.repository("https://charts.gitlab.io")
.chart("gitlab-agent")
.version("1.2.0")
.set(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference))
.build());
}
}
Content copied to clipboard
resources:
# Create token for an agent
example:
type: gitlab:ClusterAgentToken
properties:
project: '12345'
agentId: 42
description: some token
thisClusterAgent:
type: gitlab:ClusterAgent
properties:
project: ${thisProject.id}
thisClusterAgentToken:
type: gitlab:ClusterAgentToken
properties:
project: ${thisProject.id}
agentId: ${thisClusterAgent.agentId}
description: Token for the my-agent used with `gitlab-agent` Helm Chart
gitlabAgent:
type: helm:helm_release
properties:
name: gitlab-agent
namespace: gitlab-agent
createNamespace: true
repository: https://charts.gitlab.io
chart: gitlab-agent
version: 1.2.0
set:
- name: config.token
value: ${thisClusterAgentToken.token}
variables:
thisProject:
fn::invoke:
Function: gitlab:getProject
Arguments:
pathWithNamespace: my-org/example
Content copied to clipboard
Import
A token for a GitLab Agent for Kubernetes can be imported with the following command and the id pattern <project>:<agent-id>:<token-id>
:
$ pulumi import gitlab:index/clusterAgentToken:ClusterAgentToken example '12345:42:1'
Content copied to clipboard
ATTENTION: the token
resource attribute is not available for imported resources as this information cannot be read from the GitLab API.