Skip to content

Commit 55d45c5

Browse files
sawaiba-szli82016
andauthored
adding new google_secure_source_manager_branch_rule resource (#11709)
Co-authored-by: Zhenhua Li <[email protected]>
1 parent 1c7cde2 commit 55d45c5

File tree

4 files changed

+312
-0
lines changed

4 files changed

+312
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'BranchRule'
16+
description: 'BranchRule is the protection rule to enforce pre-defined rules on designated branches within a repository.'
17+
references:
18+
guides:
19+
'Official Documentation': 'https://cloud.google.com/secure-source-manager/docs/overview'
20+
docs:
21+
id_format: 'projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}/branchRules/{{branch_rule_id}}'
22+
base_url: 'projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}/branchRules?branch_rule_id={{branch_rule_id}}'
23+
self_link: 'projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}/branchRules/{{branch_rule_id}}'
24+
import_format:
25+
- 'projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}/branchRules/{{branch_rule_id}}'
26+
- '{{branch_rule_id}}'
27+
timeouts:
28+
insert_minutes: 20
29+
update_minutes: 20
30+
delete_minutes: 20
31+
autogen_async: true
32+
update_verb: 'PATCH'
33+
update_mask: true
34+
async:
35+
actions: ['create', 'delete']
36+
type: 'OpAsync'
37+
operation:
38+
base_url: '{{op_id}}'
39+
wait_ms: 1000
40+
result:
41+
path: 'response'
42+
resource_inside_response: false
43+
error:
44+
path: 'error'
45+
message: 'message'
46+
custom_code:
47+
examples:
48+
- name: 'secure_source_manager_branch_rule_basic'
49+
primary_resource_id: 'basic'
50+
vars:
51+
branch_rule_id: 'my-basic-branchrule'
52+
repository_id: 'my-basic-repository'
53+
instance_id: 'my-basic-instance'
54+
prevent_destroy: 'true'
55+
test_vars_overrides:
56+
'prevent_destroy': 'false'
57+
oics_vars_overrides:
58+
'prevent_destroy': 'false'
59+
- name: 'secure_source_manager_branch_rule_with_fields'
60+
primary_resource_id: 'default'
61+
vars:
62+
branch_rule_id: 'my-initial-branchrule'
63+
repository_id: 'my-initial-repository'
64+
instance_id: 'my-initial-instance'
65+
prevent_destroy: 'true'
66+
test_vars_overrides:
67+
'prevent_destroy': 'false'
68+
oics_vars_overrides:
69+
'prevent_destroy': 'false'
70+
parameters:
71+
- name: 'branch_rule_id'
72+
type: String
73+
description: |
74+
The ID for the BranchRule.
75+
url_param_only: true
76+
required: true
77+
- name: 'location'
78+
type: String
79+
description: |
80+
The location for the Repository.
81+
url_param_only: true
82+
required: true
83+
- name: 'repository_id'
84+
type: String
85+
description: |
86+
The ID for the Repository.
87+
url_param_only: true
88+
required: true
89+
properties:
90+
- name: 'name'
91+
type: String
92+
description: |
93+
The resource name for the BranchRule.
94+
output: true
95+
- name: 'uid'
96+
type: String
97+
description: |
98+
Unique identifier of the BranchRule.
99+
output: true
100+
- name: 'createTime'
101+
type: Time
102+
description: |
103+
Time the BranchRule was created in UTC.
104+
output: true
105+
- name: 'updateTime'
106+
type: Time
107+
description: |
108+
Time the BranchRule was updated in UTC.
109+
output: true
110+
- name: 'includePattern'
111+
type: String
112+
description: |
113+
The BranchRule matches branches based on the specified regular expression. Use .* to match all branches.
114+
required: true
115+
- name: 'disabled'
116+
type: Boolean
117+
description: |
118+
Determines if the branch rule is disabled or not.
119+
- name: 'requirePullRequest'
120+
type: Boolean
121+
description: |
122+
Determines if the branch rule requires a pull request or not.
123+
- name: 'minimumReviewsCount'
124+
type: Integer
125+
description: |
126+
The minimum number of reviews required for the branch rule to be matched.
127+
- name: 'minimumApprovalsCount'
128+
type: Integer
129+
description: |
130+
The minimum number of approvals required for the branch rule to be matched.
131+
- name: 'requireCommentsResolved'
132+
type: Boolean
133+
description: |
134+
Determines if require comments resolved before merging to the branch.
135+
- name: 'allowStaleReviews'
136+
type: Boolean
137+
description: |
138+
Determines if allow stale reviews or approvals before merging to the branch.
139+
- name: 'requireLinearHistory'
140+
type: Boolean
141+
description: |
142+
Determines if require linear history before merging to the branch.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "google_secure_source_manager_instance" "instance" {
2+
location = "us-central1"
3+
instance_id = "{{index $.Vars "instance_id"}}"
4+
# Prevent accidental deletions.
5+
lifecycle {
6+
prevent_destroy = "{{index $.Vars "prevent_destroy"}}"
7+
}
8+
}
9+
10+
resource "google_secure_source_manager_repository" "repository" {
11+
repository_id = "{{index $.Vars "repository_id"}}"
12+
location = google_secure_source_manager_instance.instance.location
13+
instance = google_secure_source_manager_instance.instance.name
14+
# Prevent accidental deletions.
15+
lifecycle {
16+
prevent_destroy = "{{index $.Vars "prevent_destroy"}}"
17+
}
18+
}
19+
20+
resource "google_secure_source_manager_branch_rule" "basic" {
21+
branch_rule_id = "{{index $.Vars "branch_rule_id"}}"
22+
repository_id = google_secure_source_manager_repository.repository.repository_id
23+
location = google_secure_source_manager_repository.repository.location
24+
# This field is required for BranchRule creation
25+
include_pattern = "main"
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "google_secure_source_manager_instance" "instance" {
2+
location = "us-central1"
3+
instance_id = "{{index $.Vars "instance_id"}}"
4+
# Prevent accidental deletions.
5+
lifecycle {
6+
prevent_destroy = "{{index $.Vars "prevent_destroy"}}"
7+
}
8+
}
9+
10+
resource "google_secure_source_manager_repository" "repository" {
11+
repository_id = "{{index $.Vars "repository_id"}}"
12+
instance = google_secure_source_manager_instance.instance.name
13+
location = google_secure_source_manager_instance.instance.location
14+
# Prevent accidental deletions.
15+
lifecycle {
16+
prevent_destroy = "{{index $.Vars "prevent_destroy"}}"
17+
}
18+
}
19+
20+
resource "google_secure_source_manager_branch_rule" "default" {
21+
branch_rule_id = "{{index $.Vars "branch_rule_id"}}"
22+
location = google_secure_source_manager_repository.repository.location
23+
repository_id = google_secure_source_manager_repository.repository.repository_id
24+
include_pattern = "test"
25+
minimum_approvals_count = 2
26+
minimum_reviews_count = 2
27+
require_comments_resolved = true
28+
require_linear_history = true
29+
require_pull_request = true
30+
disabled = false
31+
allow_stale_reviews = false
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package securesourcemanager_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-provider-google/google/acctest"
8+
)
9+
10+
func TestAccSecureSourceManagerBranchRule_secureSourceManagerBranchRuleWithFieldsExample_update(t *testing.T) {
11+
t.Parallel()
12+
13+
context := map[string]interface{}{
14+
"prevent_destroy": false,
15+
"random_suffix": acctest.RandString(t, 10),
16+
}
17+
18+
acctest.VcrTest(t, resource.TestCase{
19+
PreCheck: func() { acctest.AccTestPreCheck(t) },
20+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testAccSecureSourceManagerBranchRule_secureSourceManagerBranchRuleWithFieldsExample_full(context),
24+
},
25+
{
26+
ResourceName: "google_secure_source_manager_branch_rule.default",
27+
ImportState: true,
28+
ImportStateVerify: true,
29+
ImportStateVerifyIgnore: []string{"branch_rule_id", "location", "repository_id"},
30+
},
31+
{
32+
Config: testAccSecureSourceManagerBranchRule_secureSourceManagerBranchRuleWithFieldsExample_update(context),
33+
},
34+
{
35+
ResourceName: "google_secure_source_manager_branch_rule.default",
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
ImportStateVerifyIgnore: []string{"branch_rule_id", "location", "repository_id"},
39+
},
40+
},
41+
})
42+
}
43+
44+
func testAccSecureSourceManagerBranchRule_secureSourceManagerBranchRuleWithFieldsExample_full(context map[string]interface{}) string {
45+
return acctest.Nprintf(`
46+
resource "google_secure_source_manager_instance" "instance" {
47+
location = "us-central1"
48+
instance_id = "tf-test-my-initial-instance%{random_suffix}"
49+
# Prevent accidental deletions.
50+
lifecycle {
51+
prevent_destroy = "%{prevent_destroy}"
52+
}
53+
}
54+
55+
resource "google_secure_source_manager_repository" "repository" {
56+
repository_id = "tf-test-my-initial-repository%{random_suffix}"
57+
instance = google_secure_source_manager_instance.instance.name
58+
location = google_secure_source_manager_instance.instance.location
59+
# Prevent accidental deletions.
60+
lifecycle {
61+
prevent_destroy = "%{prevent_destroy}"
62+
}
63+
}
64+
65+
resource "google_secure_source_manager_branch_rule" "default" {
66+
branch_rule_id = "tf-test-my-initial-branchrule%{random_suffix}"
67+
location = google_secure_source_manager_repository.repository.location
68+
repository_id = google_secure_source_manager_repository.repository.repository_id
69+
include_pattern = "test"
70+
minimum_approvals_count = 2
71+
minimum_reviews_count = 2
72+
require_comments_resolved = true
73+
require_linear_history = true
74+
require_pull_request = true
75+
disabled = false
76+
allow_stale_reviews = false
77+
}
78+
`, context)
79+
}
80+
81+
func testAccSecureSourceManagerBranchRule_secureSourceManagerBranchRuleWithFieldsExample_update(context map[string]interface{}) string {
82+
return acctest.Nprintf(`
83+
resource "google_secure_source_manager_instance" "instance" {
84+
location = "us-central1"
85+
instance_id = "tf-test-my-initial-instance%{random_suffix}"
86+
# Prevent accidental deletions.
87+
lifecycle {
88+
prevent_destroy = "%{prevent_destroy}"
89+
}
90+
}
91+
92+
resource "google_secure_source_manager_repository" "repository" {
93+
repository_id = "tf-test-my-initial-repository%{random_suffix}"
94+
instance = google_secure_source_manager_instance.instance.name
95+
location = google_secure_source_manager_instance.instance.location
96+
# Prevent accidental deletions.
97+
lifecycle {
98+
prevent_destroy = "%{prevent_destroy}"
99+
}
100+
}
101+
102+
resource "google_secure_source_manager_branch_rule" "default" {
103+
branch_rule_id = "tf-test-my-initial-branchrule%{random_suffix}"
104+
location = google_secure_source_manager_repository.repository.location
105+
repository_id = google_secure_source_manager_repository.repository.repository_id
106+
include_pattern = "test"
107+
minimum_approvals_count = 1
108+
minimum_reviews_count = 1
109+
require_linear_history = false
110+
}
111+
`, context)
112+
}

0 commit comments

Comments
 (0)