1. Packages
  2. GitLab
  3. API Docs
  4. PersonalAccessToken
GitLab v8.1.0 published on Friday, Jun 21, 2024 by Pulumi

gitlab.PersonalAccessToken

Explore with Pulumi AI

gitlab logo
GitLab v8.1.0 published on Friday, Jun 21, 2024 by Pulumi

    The gitlab.PersonalAccessToken resource allows to manage the lifecycle of a personal access token for a specified user.

    This resource requires administration privileges.

    Upstream API: GitLab REST 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 scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    UserId int
    The id of the user.
    ExpiresAt string
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    Name string
    The name of the personal access token.
    Scopes []string
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    UserId int
    The id of the user.
    ExpiresAt string
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    Name string
    The name of the personal access token.
    scopes List<String>
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    userId Integer
    The id of the user.
    expiresAt String
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name String
    The name of the personal access token.
    scopes string[]
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    userId number
    The id of the user.
    expiresAt string
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name string
    The name of the personal access token.
    scopes Sequence[str]
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    user_id int
    The id of the user.
    expires_at str
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name str
    The name of the personal access token.
    scopes List<String>
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    userId Number
    The id of the user.
    expiresAt String
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    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.
    CreatedAt 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 personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    Active bool
    True if the token is active.
    CreatedAt 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 personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    active Boolean
    True if the token is active.
    createdAt 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 personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    active boolean
    True if the token is active.
    createdAt 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 personal access token. This is only populated when creating a new personal access token. This attribute 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 personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    active Boolean
    True if the token is active.
    createdAt 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 personal access token. This is only populated when creating a new personal access token. This attribute 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.
    The following state arguments are supported:
    Active bool
    True if the token is active.
    CreatedAt string
    Time the token has been created, RFC3339 format.
    ExpiresAt string
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    Name string
    The name of the personal access token.
    Revoked bool
    True if the token is revoked.
    Scopes List<string>
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    Token string
    The personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    UserId int
    The id of the user.
    Active bool
    True if the token is active.
    CreatedAt string
    Time the token has been created, RFC3339 format.
    ExpiresAt string
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    Name string
    The name of the personal access token.
    Revoked bool
    True if the token is revoked.
    Scopes []string
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    Token string
    The personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    UserId int
    The id of the user.
    active Boolean
    True if the token is active.
    createdAt String
    Time the token has been created, RFC3339 format.
    expiresAt String
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name String
    The name of the personal access token.
    revoked Boolean
    True if the token is revoked.
    scopes List<String>
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    token String
    The personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    userId Integer
    The id of the user.
    active boolean
    True if the token is active.
    createdAt string
    Time the token has been created, RFC3339 format.
    expiresAt string
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name string
    The name of the personal access token.
    revoked boolean
    True if the token is revoked.
    scopes string[]
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    token string
    The personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    userId 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
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name str
    The name of the personal access token.
    revoked bool
    True if the token is revoked.
    scopes Sequence[str]
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    token str
    The personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    user_id int
    The id of the user.
    active Boolean
    True if the token is active.
    createdAt String
    Time the token has been created, RFC3339 format.
    expiresAt String
    The token expires at midnight UTC on that date. The date must be in the format YYYY-MM-DD.
    name String
    The name of the personal access token.
    revoked Boolean
    True if the token is revoked.
    scopes List<String>
    The scope for the personal access token. It determines the actions which can be performed when authenticating with this token. Valid values are: api, read_user, read_api, read_repository, write_repository, read_registry, write_registry, sudo, admin_mode, create_runner, manage_runner.
    token String
    The personal access token. This is only populated when creating a new personal access token. This attribute is not available for imported resources.
    userId 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.
    gitlab logo
    GitLab v8.1.0 published on Friday, Jun 21, 2024 by Pulumi