1. Packages
  2. GitLab
  3. API Docs
  4. ClusterAgent
GitLab v8.0.0 published on Thursday, May 30, 2024 by Pulumi

gitlab.ClusterAgent

Explore with Pulumi AI

gitlab logo
GitLab v8.0.0 published on Thursday, May 30, 2024 by Pulumi

    The gitlab.ClusterAgent resource allows to manage the lifecycle of a GitLab Agent for Kubernetes.

    Note that this resource only registers the agent, but doesn’t configure it. The configuration needs to be manually added as described in the docs. However, a gitlab.RepositoryFile resource may be used to achieve that.

    Requires at least maintainer permissions on the project.

    Requires at least GitLab 14.10

    Upstream API: GitLab REST API docs

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as gitlab from "@pulumi/gitlab";
    import * as std from "@pulumi/std";
    
    const example = new gitlab.ClusterAgent("example", {
        project: "12345",
        name: "agent-1",
    });
    // Optionally, configure the agent as described in
    // https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
    const exampleAgentConfig = new gitlab.RepositoryFile("example_agent_config", {
        project: example.project,
        branch: "main",
        filePath: pulumi.interpolate`.gitlab/agents/${example.name}/config.yaml`,
        content: std.base64encode({
            input: "# the GitLab Agent for Kubernetes configuration goes here ...\n",
        }).then(invoke => invoke.result),
        authorEmail: "terraform@example.com",
        authorName: "Terraform",
        commitMessage: pulumi.interpolate`feature: add agent config for ${example.name} [skip ci]`,
    });
    
    import pulumi
    import pulumi_gitlab as gitlab
    import pulumi_std as std
    
    example = gitlab.ClusterAgent("example",
        project="12345",
        name="agent-1")
    # Optionally, configure the agent as described in
    # https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
    example_agent_config = gitlab.RepositoryFile("example_agent_config",
        project=example.project,
        branch="main",
        file_path=example.name.apply(lambda name: f".gitlab/agents/{name}/config.yaml"),
        content=std.base64encode(input="# the GitLab Agent for Kubernetes configuration goes here ...\n").result,
        author_email="terraform@example.com",
        author_name="Terraform",
        commit_message=example.name.apply(lambda name: f"feature: add agent config for {name} [skip ci]"))
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-gitlab/sdk/v8/go/gitlab"
    	"github.com/pulumi/pulumi-std/sdk/go/std"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := gitlab.NewClusterAgent(ctx, "example", &gitlab.ClusterAgentArgs{
    			Project: pulumi.String("12345"),
    			Name:    pulumi.String("agent-1"),
    		})
    		if err != nil {
    			return err
    		}
    		invokeBase64encode, err := std.Base64encode(ctx, &std.Base64encodeArgs{
    			Input: "# the GitLab Agent for Kubernetes configuration goes here ...\n",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Optionally, configure the agent as described in
    		// https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
    		_, err = gitlab.NewRepositoryFile(ctx, "example_agent_config", &gitlab.RepositoryFileArgs{
    			Project: example.Project,
    			Branch:  pulumi.String("main"),
    			FilePath: example.Name.ApplyT(func(name string) (string, error) {
    				return fmt.Sprintf(".gitlab/agents/%v/config.yaml", name), nil
    			}).(pulumi.StringOutput),
    			Content:     invokeBase64encode.Result,
    			AuthorEmail: pulumi.String("terraform@example.com"),
    			AuthorName:  pulumi.String("Terraform"),
    			CommitMessage: example.Name.ApplyT(func(name string) (string, error) {
    				return fmt.Sprintf("feature: add agent config for %v [skip ci]", name), nil
    			}).(pulumi.StringOutput),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using GitLab = Pulumi.GitLab;
    using Std = Pulumi.Std;
    
    return await Deployment.RunAsync(() => 
    {
        var example = new GitLab.ClusterAgent("example", new()
        {
            Project = "12345",
            Name = "agent-1",
        });
    
        // Optionally, configure the agent as described in
        // https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
        var exampleAgentConfig = new GitLab.RepositoryFile("example_agent_config", new()
        {
            Project = example.Project,
            Branch = "main",
            FilePath = example.Name.Apply(name => $".gitlab/agents/{name}/config.yaml"),
            Content = Std.Base64encode.Invoke(new()
            {
                Input = @"# the GitLab Agent for Kubernetes configuration goes here ...
    ",
            }).Apply(invoke => invoke.Result),
            AuthorEmail = "terraform@example.com",
            AuthorName = "Terraform",
            CommitMessage = example.Name.Apply(name => $"feature: add agent config for {name} [skip ci]"),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.gitlab.ClusterAgent;
    import com.pulumi.gitlab.ClusterAgentArgs;
    import com.pulumi.gitlab.RepositoryFile;
    import com.pulumi.gitlab.RepositoryFileArgs;
    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 ClusterAgent("example", ClusterAgentArgs.builder()
                .project("12345")
                .name("agent-1")
                .build());
    
            // Optionally, configure the agent as described in
            // https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
            var exampleAgentConfig = new RepositoryFile("exampleAgentConfig", RepositoryFileArgs.builder()
                .project(example.project())
                .branch("main")
                .filePath(example.name().applyValue(name -> String.format(".gitlab/agents/%s/config.yaml", name)))
                .content(StdFunctions.base64encode(Base64encodeArgs.builder()
                    .input("""
    # the GitLab Agent for Kubernetes configuration goes here ...
                    """)
                    .build()).result())
                .authorEmail("terraform@example.com")
                .authorName("Terraform")
                .commitMessage(example.name().applyValue(name -> String.format("feature: add agent config for %s [skip ci]", name)))
                .build());
    
        }
    }
    
    resources:
      example:
        type: gitlab:ClusterAgent
        properties:
          project: '12345'
          name: agent-1
      # Optionally, configure the agent as described in
      # // https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
      exampleAgentConfig:
        type: gitlab:RepositoryFile
        name: example_agent_config
        properties:
          project: ${example.project}
          branch: main
          filePath: .gitlab/agents/${example.name}/config.yaml
          content:
            fn::invoke:
              Function: std:base64encode
              Arguments:
                input: |
                  # the GitLab Agent for Kubernetes configuration goes here ...              
              Return: result
          authorEmail: terraform@example.com
          authorName: Terraform
          commitMessage: 'feature: add agent config for ${example.name} [skip ci]'
    

    Create ClusterAgent Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new ClusterAgent(name: string, args: ClusterAgentArgs, opts?: CustomResourceOptions);
    @overload
    def ClusterAgent(resource_name: str,
                     args: ClusterAgentArgs,
                     opts: Optional[ResourceOptions] = None)
    
    @overload
    def ClusterAgent(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     project: Optional[str] = None,
                     name: Optional[str] = None)
    func NewClusterAgent(ctx *Context, name string, args ClusterAgentArgs, opts ...ResourceOption) (*ClusterAgent, error)
    public ClusterAgent(string name, ClusterAgentArgs args, CustomResourceOptions? opts = null)
    public ClusterAgent(String name, ClusterAgentArgs args)
    public ClusterAgent(String name, ClusterAgentArgs args, CustomResourceOptions options)
    
    type: gitlab:ClusterAgent
    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 ClusterAgentArgs
    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 ClusterAgentArgs
    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 ClusterAgentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args ClusterAgentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args ClusterAgentArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Example

    The following reference example uses placeholder values for all input properties.

    var clusterAgentResource = new GitLab.ClusterAgent("clusterAgentResource", new()
    {
        Project = "string",
        Name = "string",
    });
    
    example, err := gitlab.NewClusterAgent(ctx, "clusterAgentResource", &gitlab.ClusterAgentArgs{
    	Project: pulumi.String("string"),
    	Name:    pulumi.String("string"),
    })
    
    var clusterAgentResource = new ClusterAgent("clusterAgentResource", ClusterAgentArgs.builder()
        .project("string")
        .name("string")
        .build());
    
    cluster_agent_resource = gitlab.ClusterAgent("clusterAgentResource",
        project="string",
        name="string")
    
    const clusterAgentResource = new gitlab.ClusterAgent("clusterAgentResource", {
        project: "string",
        name: "string",
    });
    
    type: gitlab:ClusterAgent
    properties:
        name: string
        project: string
    

    ClusterAgent 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 ClusterAgent resource accepts the following input properties:

    Project string
    ID or full path of the project maintained by the authenticated user.
    Name string
    The Name of the agent.
    Project string
    ID or full path of the project maintained by the authenticated user.
    Name string
    The Name of the agent.
    project String
    ID or full path of the project maintained by the authenticated user.
    name String
    The Name of the agent.
    project string
    ID or full path of the project maintained by the authenticated user.
    name string
    The Name of the agent.
    project str
    ID or full path of the project maintained by the authenticated user.
    name str
    The Name of the agent.
    project String
    ID or full path of the project maintained by the authenticated user.
    name String
    The Name of the agent.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the ClusterAgent resource produces the following output properties:

    AgentId int
    The ID of the agent.
    CreatedAt string
    The ISO8601 datetime when the agent was created.
    CreatedByUserId int
    The ID of the user who created the agent.
    Id string
    The provider-assigned unique ID for this managed resource.
    AgentId int
    The ID of the agent.
    CreatedAt string
    The ISO8601 datetime when the agent was created.
    CreatedByUserId int
    The ID of the user who created the agent.
    Id string
    The provider-assigned unique ID for this managed resource.
    agentId Integer
    The ID of the agent.
    createdAt String
    The ISO8601 datetime when the agent was created.
    createdByUserId Integer
    The ID of the user who created the agent.
    id String
    The provider-assigned unique ID for this managed resource.
    agentId number
    The ID of the agent.
    createdAt string
    The ISO8601 datetime when the agent was created.
    createdByUserId number
    The ID of the user who created the agent.
    id string
    The provider-assigned unique ID for this managed resource.
    agent_id int
    The ID of the agent.
    created_at str
    The ISO8601 datetime when the agent was created.
    created_by_user_id int
    The ID of the user who created the agent.
    id str
    The provider-assigned unique ID for this managed resource.
    agentId Number
    The ID of the agent.
    createdAt String
    The ISO8601 datetime when the agent was created.
    createdByUserId Number
    The ID of the user who created the agent.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing ClusterAgent Resource

    Get an existing ClusterAgent 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?: ClusterAgentState, opts?: CustomResourceOptions): ClusterAgent
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            agent_id: Optional[int] = None,
            created_at: Optional[str] = None,
            created_by_user_id: Optional[int] = None,
            name: Optional[str] = None,
            project: Optional[str] = None) -> ClusterAgent
    func GetClusterAgent(ctx *Context, name string, id IDInput, state *ClusterAgentState, opts ...ResourceOption) (*ClusterAgent, error)
    public static ClusterAgent Get(string name, Input<string> id, ClusterAgentState? state, CustomResourceOptions? opts = null)
    public static ClusterAgent get(String name, Output<String> id, ClusterAgentState 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:
    AgentId int
    The ID of the agent.
    CreatedAt string
    The ISO8601 datetime when the agent was created.
    CreatedByUserId int
    The ID of the user who created the agent.
    Name string
    The Name of the agent.
    Project string
    ID or full path of the project maintained by the authenticated user.
    AgentId int
    The ID of the agent.
    CreatedAt string
    The ISO8601 datetime when the agent was created.
    CreatedByUserId int
    The ID of the user who created the agent.
    Name string
    The Name of the agent.
    Project string
    ID or full path of the project maintained by the authenticated user.
    agentId Integer
    The ID of the agent.
    createdAt String
    The ISO8601 datetime when the agent was created.
    createdByUserId Integer
    The ID of the user who created the agent.
    name String
    The Name of the agent.
    project String
    ID or full path of the project maintained by the authenticated user.
    agentId number
    The ID of the agent.
    createdAt string
    The ISO8601 datetime when the agent was created.
    createdByUserId number
    The ID of the user who created the agent.
    name string
    The Name of the agent.
    project string
    ID or full path of the project maintained by the authenticated user.
    agent_id int
    The ID of the agent.
    created_at str
    The ISO8601 datetime when the agent was created.
    created_by_user_id int
    The ID of the user who created the agent.
    name str
    The Name of the agent.
    project str
    ID or full path of the project maintained by the authenticated user.
    agentId Number
    The ID of the agent.
    createdAt String
    The ISO8601 datetime when the agent was created.
    createdByUserId Number
    The ID of the user who created the agent.
    name String
    The Name of the agent.
    project String
    ID or full path of the project maintained by the authenticated user.

    Import

    GitLab Agent for Kubernetes can be imported with the following command and the id pattern <project>:<agent-id>

    $ pulumi import gitlab:index/clusterAgent:ClusterAgent example '12345:42'
    

    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.0.0 published on Thursday, May 30, 2024 by Pulumi