1. Packages
  2. Gitlab Provider
  3. API Docs
  4. ProjectTargetBranchRule
GitLab v9.2.0 published on Friday, Jul 18, 2025 by Pulumi

gitlab.ProjectTargetBranchRule

Explore with Pulumi AI

gitlab logo
GitLab v9.2.0 published on Friday, Jul 18, 2025 by Pulumi

    The gitlab.ProjectTargetBranchRule resource manages default target branch rules when creating merge requests.

    Upstream API: GitLab GraphQL API docs

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as gitlab from "@pulumi/gitlab";
    
    const example = new gitlab.Project("example", {
        name: "example project",
        description: "Lorem Ipsum",
        visibilityLevel: "public",
    });
    // Basic example
    const rule = new gitlab.ProjectTargetBranchRule("rule", {
        project: example.id,
        sourceBranchPattern: "develop",
        targetBranchName: "release",
    });
    
    import pulumi
    import pulumi_gitlab as gitlab
    
    example = gitlab.Project("example",
        name="example project",
        description="Lorem Ipsum",
        visibility_level="public")
    # Basic example
    rule = gitlab.ProjectTargetBranchRule("rule",
        project=example.id,
        source_branch_pattern="develop",
        target_branch_name="release")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-gitlab/sdk/v9/go/gitlab"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := gitlab.NewProject(ctx, "example", &gitlab.ProjectArgs{
    			Name:            pulumi.String("example project"),
    			Description:     pulumi.String("Lorem Ipsum"),
    			VisibilityLevel: pulumi.String("public"),
    		})
    		if err != nil {
    			return err
    		}
    		// Basic example
    		_, err = gitlab.NewProjectTargetBranchRule(ctx, "rule", &gitlab.ProjectTargetBranchRuleArgs{
    			Project:             example.ID(),
    			SourceBranchPattern: pulumi.String("develop"),
    			TargetBranchName:    pulumi.String("release"),
    		})
    		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.Project("example", new()
        {
            Name = "example project",
            Description = "Lorem Ipsum",
            VisibilityLevel = "public",
        });
    
        // Basic example
        var rule = new GitLab.ProjectTargetBranchRule("rule", new()
        {
            Project = example.Id,
            SourceBranchPattern = "develop",
            TargetBranchName = "release",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.gitlab.Project;
    import com.pulumi.gitlab.ProjectArgs;
    import com.pulumi.gitlab.ProjectTargetBranchRule;
    import com.pulumi.gitlab.ProjectTargetBranchRuleArgs;
    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 Project("example", ProjectArgs.builder()
                .name("example project")
                .description("Lorem Ipsum")
                .visibilityLevel("public")
                .build());
    
            // Basic example
            var rule = new ProjectTargetBranchRule("rule", ProjectTargetBranchRuleArgs.builder()
                .project(example.id())
                .sourceBranchPattern("develop")
                .targetBranchName("release")
                .build());
    
        }
    }
    
    resources:
      example:
        type: gitlab:Project
        properties:
          name: example project
          description: Lorem Ipsum
          visibilityLevel: public
      # Basic example
      rule:
        type: gitlab:ProjectTargetBranchRule
        properties:
          project: ${example.id}
          sourceBranchPattern: develop
          targetBranchName: release
    

    Create ProjectTargetBranchRule Resource

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

    Constructor syntax

    new ProjectTargetBranchRule(name: string, args: ProjectTargetBranchRuleArgs, opts?: CustomResourceOptions);
    @overload
    def ProjectTargetBranchRule(resource_name: str,
                                args: ProjectTargetBranchRuleArgs,
                                opts: Optional[ResourceOptions] = None)
    
    @overload
    def ProjectTargetBranchRule(resource_name: str,
                                opts: Optional[ResourceOptions] = None,
                                project: Optional[str] = None,
                                source_branch_pattern: Optional[str] = None,
                                target_branch_name: Optional[str] = None)
    func NewProjectTargetBranchRule(ctx *Context, name string, args ProjectTargetBranchRuleArgs, opts ...ResourceOption) (*ProjectTargetBranchRule, error)
    public ProjectTargetBranchRule(string name, ProjectTargetBranchRuleArgs args, CustomResourceOptions? opts = null)
    public ProjectTargetBranchRule(String name, ProjectTargetBranchRuleArgs args)
    public ProjectTargetBranchRule(String name, ProjectTargetBranchRuleArgs args, CustomResourceOptions options)
    
    type: gitlab:ProjectTargetBranchRule
    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 ProjectTargetBranchRuleArgs
    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 ProjectTargetBranchRuleArgs
    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 ProjectTargetBranchRuleArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args ProjectTargetBranchRuleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args ProjectTargetBranchRuleArgs
    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 projectTargetBranchRuleResource = new GitLab.ProjectTargetBranchRule("projectTargetBranchRuleResource", new()
    {
        Project = "string",
        SourceBranchPattern = "string",
        TargetBranchName = "string",
    });
    
    example, err := gitlab.NewProjectTargetBranchRule(ctx, "projectTargetBranchRuleResource", &gitlab.ProjectTargetBranchRuleArgs{
    	Project:             pulumi.String("string"),
    	SourceBranchPattern: pulumi.String("string"),
    	TargetBranchName:    pulumi.String("string"),
    })
    
    var projectTargetBranchRuleResource = new ProjectTargetBranchRule("projectTargetBranchRuleResource", ProjectTargetBranchRuleArgs.builder()
        .project("string")
        .sourceBranchPattern("string")
        .targetBranchName("string")
        .build());
    
    project_target_branch_rule_resource = gitlab.ProjectTargetBranchRule("projectTargetBranchRuleResource",
        project="string",
        source_branch_pattern="string",
        target_branch_name="string")
    
    const projectTargetBranchRuleResource = new gitlab.ProjectTargetBranchRule("projectTargetBranchRuleResource", {
        project: "string",
        sourceBranchPattern: "string",
        targetBranchName: "string",
    });
    
    type: gitlab:ProjectTargetBranchRule
    properties:
        project: string
        sourceBranchPattern: string
        targetBranchName: string
    

    ProjectTargetBranchRule Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The ProjectTargetBranchRule resource accepts the following input properties:

    Project string
    The ID or URL-encoded path of the project.
    SourceBranchPattern string
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    TargetBranchName string
    The name of the branch to which the merge request should be addressed.
    Project string
    The ID or URL-encoded path of the project.
    SourceBranchPattern string
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    TargetBranchName string
    The name of the branch to which the merge request should be addressed.
    project String
    The ID or URL-encoded path of the project.
    sourceBranchPattern String
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    targetBranchName String
    The name of the branch to which the merge request should be addressed.
    project string
    The ID or URL-encoded path of the project.
    sourceBranchPattern string
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    targetBranchName string
    The name of the branch to which the merge request should be addressed.
    project str
    The ID or URL-encoded path of the project.
    source_branch_pattern str
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    target_branch_name str
    The name of the branch to which the merge request should be addressed.
    project String
    The ID or URL-encoded path of the project.
    sourceBranchPattern String
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    targetBranchName String
    The name of the branch to which the merge request should be addressed.

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing ProjectTargetBranchRule Resource

    Get an existing ProjectTargetBranchRule 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?: ProjectTargetBranchRuleState, opts?: CustomResourceOptions): ProjectTargetBranchRule
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            project: Optional[str] = None,
            source_branch_pattern: Optional[str] = None,
            target_branch_name: Optional[str] = None) -> ProjectTargetBranchRule
    func GetProjectTargetBranchRule(ctx *Context, name string, id IDInput, state *ProjectTargetBranchRuleState, opts ...ResourceOption) (*ProjectTargetBranchRule, error)
    public static ProjectTargetBranchRule Get(string name, Input<string> id, ProjectTargetBranchRuleState? state, CustomResourceOptions? opts = null)
    public static ProjectTargetBranchRule get(String name, Output<String> id, ProjectTargetBranchRuleState state, CustomResourceOptions options)
    resources:  _:    type: gitlab:ProjectTargetBranchRule    get:      id: ${id}
    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:
    Project string
    The ID or URL-encoded path of the project.
    SourceBranchPattern string
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    TargetBranchName string
    The name of the branch to which the merge request should be addressed.
    Project string
    The ID or URL-encoded path of the project.
    SourceBranchPattern string
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    TargetBranchName string
    The name of the branch to which the merge request should be addressed.
    project String
    The ID or URL-encoded path of the project.
    sourceBranchPattern String
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    targetBranchName String
    The name of the branch to which the merge request should be addressed.
    project string
    The ID or URL-encoded path of the project.
    sourceBranchPattern string
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    targetBranchName string
    The name of the branch to which the merge request should be addressed.
    project str
    The ID or URL-encoded path of the project.
    source_branch_pattern str
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    target_branch_name str
    The name of the branch to which the merge request should be addressed.
    project String
    The ID or URL-encoded path of the project.
    sourceBranchPattern String
    A pattern matching the branch name for which the merge request should have a default target branch configured.
    targetBranchName String
    The name of the branch to which the merge request should be addressed.

    Import

    Starting in Terraform v1.5.0, you can use an import block to import gitlab_project_target_branch_rule. For example:

    terraform

    import {

    to = gitlab_project_target_branch_rule.example

    id = “see CLI command below for ID”

    }

    Importing using the CLI is supported with the following syntax:

    A GitLab Project targer branch rule can be imported using a key composed of <project-id>:<target-branch-rule-id>, for example:

    $ pulumi import gitlab:index/projectTargetBranchRule:ProjectTargetBranchRule example "12345:1"
    

    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 v9.2.0 published on Friday, Jul 18, 2025 by Pulumi