gitlab.PersonalAccessToken
Explore with Pulumi AI
The gitlab.PersonalAccessToken
resource allows to manage the lifecycle of a personal access token.
This resource requires administration privileges.
Use of the
timestamp()
function with expires_at will cause the resource to be re-created with every apply, it’s recommended to useplantimestamp()
or a static value instead.
Observability scopes are in beta and may not work on all instances. See more details in the documentation
Due to Automatic reuse detection it’s possible that a new Personal Access Token will immediately be revoked. Check if an old process using the old token is running if this happens.
Upstream API: GitLab API docs
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as gitlab from "@pulumi/gitlab";
const example = new gitlab.PersonalAccessToken("example", {
userId: 25,
name: "Example personal access token",
expiresAt: "2020-03-14",
scopes: ["api"],
});
const exampleProjectVariable = new gitlab.ProjectVariable("example", {
project: exampleGitlabProject.id,
key: "pat",
value: example.token,
});
import pulumi
import pulumi_gitlab as gitlab
example = gitlab.PersonalAccessToken("example",
user_id=25,
name="Example personal access token",
expires_at="2020-03-14",
scopes=["api"])
example_project_variable = gitlab.ProjectVariable("example",
project=example_gitlab_project["id"],
key="pat",
value=example.token)
package main
import (
"github.com/pulumi/pulumi-gitlab/sdk/v8/go/gitlab"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := gitlab.NewPersonalAccessToken(ctx, "example", &gitlab.PersonalAccessTokenArgs{
UserId: pulumi.Int(25),
Name: pulumi.String("Example personal access token"),
ExpiresAt: pulumi.String("2020-03-14"),
Scopes: pulumi.StringArray{
pulumi.String("api"),
},
})
if err != nil {
return err
}
_, err = gitlab.NewProjectVariable(ctx, "example", &gitlab.ProjectVariableArgs{
Project: pulumi.Any(exampleGitlabProject.Id),
Key: pulumi.String("pat"),
Value: example.Token,
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using GitLab = Pulumi.GitLab;
return await Deployment.RunAsync(() =>
{
var example = new GitLab.PersonalAccessToken("example", new()
{
UserId = 25,
Name = "Example personal access token",
ExpiresAt = "2020-03-14",
Scopes = new[]
{
"api",
},
});
var exampleProjectVariable = new GitLab.ProjectVariable("example", new()
{
Project = exampleGitlabProject.Id,
Key = "pat",
Value = example.Token,
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gitlab.PersonalAccessToken;
import com.pulumi.gitlab.PersonalAccessTokenArgs;
import com.pulumi.gitlab.ProjectVariable;
import com.pulumi.gitlab.ProjectVariableArgs;
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) {
var example = new PersonalAccessToken("example", PersonalAccessTokenArgs.builder()
.userId("25")
.name("Example personal access token")
.expiresAt("2020-03-14")
.scopes("api")
.build());
var exampleProjectVariable = new ProjectVariable("exampleProjectVariable", ProjectVariableArgs.builder()
.project(exampleGitlabProject.id())
.key("pat")
.value(example.token())
.build());
}
}
resources:
example:
type: gitlab:PersonalAccessToken
properties:
userId: '25'
name: Example personal access token
expiresAt: 2020-03-14
scopes:
- api
exampleProjectVariable:
type: gitlab:ProjectVariable
name: example
properties:
project: ${exampleGitlabProject.id}
key: pat
value: ${example.token}
Create PersonalAccessToken Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new PersonalAccessToken(name: string, args: PersonalAccessTokenArgs, opts?: CustomResourceOptions);
@overload
def PersonalAccessToken(resource_name: str,
args: PersonalAccessTokenArgs,
opts: Optional[ResourceOptions] = None)
@overload
def PersonalAccessToken(resource_name: str,
opts: Optional[ResourceOptions] = None,
scopes: Optional[Sequence[str]] = None,
user_id: Optional[int] = None,
expires_at: Optional[str] = None,
name: Optional[str] = None)
func NewPersonalAccessToken(ctx *Context, name string, args PersonalAccessTokenArgs, opts ...ResourceOption) (*PersonalAccessToken, error)
public PersonalAccessToken(string name, PersonalAccessTokenArgs args, CustomResourceOptions? opts = null)
public PersonalAccessToken(String name, PersonalAccessTokenArgs args)
public PersonalAccessToken(String name, PersonalAccessTokenArgs args, CustomResourceOptions options)
type: gitlab:PersonalAccessToken
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args PersonalAccessTokenArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args PersonalAccessTokenArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args PersonalAccessTokenArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args PersonalAccessTokenArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args PersonalAccessTokenArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var personalAccessTokenResource = new GitLab.PersonalAccessToken("personalAccessTokenResource", new()
{
Scopes = new[]
{
"string",
},
UserId = 0,
ExpiresAt = "string",
Name = "string",
});
example, err := gitlab.NewPersonalAccessToken(ctx, "personalAccessTokenResource", &gitlab.PersonalAccessTokenArgs{
Scopes: pulumi.StringArray{
pulumi.String("string"),
},
UserId: pulumi.Int(0),
ExpiresAt: pulumi.String("string"),
Name: pulumi.String("string"),
})
var personalAccessTokenResource = new PersonalAccessToken("personalAccessTokenResource", PersonalAccessTokenArgs.builder()
.scopes("string")
.userId(0)
.expiresAt("string")
.name("string")
.build());
personal_access_token_resource = gitlab.PersonalAccessToken("personalAccessTokenResource",
scopes=["string"],
user_id=0,
expires_at="string",
name="string")
const personalAccessTokenResource = new gitlab.PersonalAccessToken("personalAccessTokenResource", {
scopes: ["string"],
userId: 0,
expiresAt: "string",
name: "string",
});
type: gitlab:PersonalAccessToken
properties:
expiresAt: string
name: string
scopes:
- string
userId: 0
PersonalAccessToken Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The PersonalAccessToken resource accepts the following input properties:
- Scopes List<string>
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- User
Id int - The ID of the user.
- Expires
At string - When the token will expire, YYYY-MM-DD format.
- Name string
- The name of the personal access token.
- Scopes []string
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- User
Id int - The ID of the user.
- Expires
At string - When the token will expire, YYYY-MM-DD format.
- Name string
- The name of the personal access token.
- scopes List<String>
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- user
Id Integer - The ID of the user.
- expires
At String - When the token will expire, YYYY-MM-DD format.
- name String
- The name of the personal access token.
- scopes string[]
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- user
Id number - The ID of the user.
- expires
At string - When the token will expire, YYYY-MM-DD format.
- name string
- The name of the personal access token.
- scopes Sequence[str]
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- user_
id int - The ID of the user.
- expires_
at str - When the token will expire, YYYY-MM-DD format.
- name str
- The name of the personal access token.
- scopes List<String>
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- user
Id Number - The ID of the user.
- expires
At String - When the token will expire, YYYY-MM-DD format.
- name String
- The name of the personal access token.
Outputs
All input properties are implicitly available as output properties. Additionally, the PersonalAccessToken resource produces the following output properties:
- Active bool
- True if the token is active.
- Created
At string - Time the token has been created, RFC3339 format.
- Id string
- The provider-assigned unique ID for this managed resource.
- Revoked bool
- True if the token is revoked.
- Token string
- The token of the personal access token. Note: the token is not available for imported resources.
- Active bool
- True if the token is active.
- Created
At string - Time the token has been created, RFC3339 format.
- Id string
- The provider-assigned unique ID for this managed resource.
- Revoked bool
- True if the token is revoked.
- Token string
- The token of the personal access token. Note: the token is not available for imported resources.
- active Boolean
- True if the token is active.
- created
At String - Time the token has been created, RFC3339 format.
- id String
- The provider-assigned unique ID for this managed resource.
- revoked Boolean
- True if the token is revoked.
- token String
- The token of the personal access token. Note: the token is not available for imported resources.
- active boolean
- True if the token is active.
- created
At string - Time the token has been created, RFC3339 format.
- id string
- The provider-assigned unique ID for this managed resource.
- revoked boolean
- True if the token is revoked.
- token string
- The token of the personal access token. Note: the token is not available for imported resources.
- active bool
- True if the token is active.
- created_
at str - Time the token has been created, RFC3339 format.
- id str
- The provider-assigned unique ID for this managed resource.
- revoked bool
- True if the token is revoked.
- token str
- The token of the personal access token. Note: the token is not available for imported resources.
- active Boolean
- True if the token is active.
- created
At String - Time the token has been created, RFC3339 format.
- id String
- The provider-assigned unique ID for this managed resource.
- revoked Boolean
- True if the token is revoked.
- token String
- The token of the personal access token. Note: the token is not available for imported resources.
Look up Existing PersonalAccessToken Resource
Get an existing PersonalAccessToken resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: PersonalAccessTokenState, opts?: CustomResourceOptions): PersonalAccessToken
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
active: Optional[bool] = None,
created_at: Optional[str] = None,
expires_at: Optional[str] = None,
name: Optional[str] = None,
revoked: Optional[bool] = None,
scopes: Optional[Sequence[str]] = None,
token: Optional[str] = None,
user_id: Optional[int] = None) -> PersonalAccessToken
func GetPersonalAccessToken(ctx *Context, name string, id IDInput, state *PersonalAccessTokenState, opts ...ResourceOption) (*PersonalAccessToken, error)
public static PersonalAccessToken Get(string name, Input<string> id, PersonalAccessTokenState? state, CustomResourceOptions? opts = null)
public static PersonalAccessToken get(String name, Output<String> id, PersonalAccessTokenState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Active bool
- True if the token is active.
- Created
At string - Time the token has been created, RFC3339 format.
- Expires
At string - When the token will expire, YYYY-MM-DD format.
- Name string
- The name of the personal access token.
- Revoked bool
- True if the token is revoked.
- Scopes List<string>
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- Token string
- The token of the personal access token. Note: the token is not available for imported resources.
- User
Id int - The ID of the user.
- Active bool
- True if the token is active.
- Created
At string - Time the token has been created, RFC3339 format.
- Expires
At string - When the token will expire, YYYY-MM-DD format.
- Name string
- The name of the personal access token.
- Revoked bool
- True if the token is revoked.
- Scopes []string
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- Token string
- The token of the personal access token. Note: the token is not available for imported resources.
- User
Id int - The ID of the user.
- active Boolean
- True if the token is active.
- created
At String - Time the token has been created, RFC3339 format.
- expires
At String - When the token will expire, YYYY-MM-DD format.
- name String
- The name of the personal access token.
- revoked Boolean
- True if the token is revoked.
- scopes List<String>
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- token String
- The token of the personal access token. Note: the token is not available for imported resources.
- user
Id Integer - The ID of the user.
- active boolean
- True if the token is active.
- created
At string - Time the token has been created, RFC3339 format.
- expires
At string - When the token will expire, YYYY-MM-DD format.
- name string
- The name of the personal access token.
- revoked boolean
- True if the token is revoked.
- scopes string[]
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- token string
- The token of the personal access token. Note: the token is not available for imported resources.
- user
Id number - The ID of the user.
- active bool
- True if the token is active.
- created_
at str - Time the token has been created, RFC3339 format.
- expires_
at str - When the token will expire, YYYY-MM-DD format.
- name str
- The name of the personal access token.
- revoked bool
- True if the token is revoked.
- scopes Sequence[str]
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- token str
- The token of the personal access token. Note: the token is not available for imported resources.
- user_
id int - The ID of the user.
- active Boolean
- True if the token is active.
- created
At String - Time the token has been created, RFC3339 format.
- expires
At String - When the token will expire, YYYY-MM-DD format.
- name String
- The name of the personal access token.
- revoked Boolean
- True if the token is revoked.
- scopes List<String>
- The scopes of the personal access token. valid values are:
api
,read_user
,read_api
,read_repository
,write_repository
,read_registry
,write_registry
,sudo
,admin_mode
,create_runner
,manage_runner
,ai_features
,k8s_proxy
,read_service_ping
- token String
- The token of the personal access token. Note: the token is not available for imported resources.
- user
Id Number - The ID of the user.
Import
A GitLab Personal Access Token can be imported using a key composed of <user-id>:<token-id>
, e.g.
$ pulumi import gitlab:index/personalAccessToken:PersonalAccessToken example "12345:1"
NOTE: the token
resource attribute is not available for imported resources as this information cannot be read from the GitLab API.
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- GitLab pulumi/pulumi-gitlab
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
gitlab
Terraform Provider.