Skip to content

Commit b5b16ac

Browse files
authored
Migrate google_eventarc_channel resource from DCL to MMv1 (#13026)
1 parent 5662a5b commit b5b16ac

File tree

15 files changed

+275
-280
lines changed

15 files changed

+275
-280
lines changed

mmv1/api/resource/examples.go

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (e *Examples) SetHCLText() {
228228
docTestEnvVars := make(map[string]string)
229229
docs_defaults := map[string]string{
230230
"PROJECT_NAME": "my-project-name",
231+
"PROJECT_NUMBER": "1111111111111",
231232
"CREDENTIALS": "my/credentials/filename.json",
232233
"REGION": "us-west1",
233234
"ORG_ID": "123456789",

mmv1/products/eventarc/Channel.yaml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Copyright 2025 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: Channel
16+
legacy_long_form_project: true
17+
base_url: projects/{{project}}/locations/{{location}}/channels
18+
create_url: projects/{{project}}/locations/{{location}}/channels?channelId={{name}}
19+
self_link: projects/{{project}}/locations/{{location}}/channels/{{name}}
20+
update_verb: PATCH
21+
update_mask: true
22+
references:
23+
guides:
24+
'Official Documentation': 'https://cloud.google.com/eventarc/standard/docs/third-parties/create-channels'
25+
api: https://cloud.google.com/eventarc/docs/reference/rest/v1/projects.locations.channels
26+
async:
27+
actions: ['create', 'update', 'delete']
28+
type: OpAsync
29+
operation:
30+
base_url: '{{op_id}}'
31+
result:
32+
resource_inside_response: true
33+
autogen_async: true
34+
description: |
35+
The Eventarc Channel resource
36+
error_retry_predicates:
37+
- transport_tpg.EventarcChannel403Retry
38+
examples:
39+
- name: eventarc_channel_with_cmek
40+
primary_resource_id: primary
41+
bootstrap_iam:
42+
- member: "serviceAccount:service-{project_number}@gcp-sa-eventarc.iam.gserviceaccount.com"
43+
role: "roles/cloudkms.cryptoKeyEncrypterDecrypter"
44+
vars:
45+
channel_name: some-channel
46+
key_name: some-key
47+
test_env_vars:
48+
project: 'PROJECT_NAME'
49+
project_number: 'PROJECT_NUMBER'
50+
test_vars_overrides:
51+
'key_name': 'acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", "us-central1", "tf-bootstrap-eventarc-channel-key").CryptoKey.Name'
52+
- name: eventarc_channel
53+
primary_resource_id: primary
54+
vars:
55+
channel_name: some-channel
56+
exclude_docs: true
57+
parameters:
58+
- name: location
59+
type: String
60+
description: The location for the resource
61+
url_param_only: true
62+
required: true
63+
immutable: true
64+
properties:
65+
- name: name
66+
type: String
67+
description: The resource name of the channel. Must be unique within the location on the project.
68+
required: true
69+
immutable: true
70+
diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName
71+
custom_expand: templates/terraform/custom_expand/eventarc_channel_name.go.tmpl
72+
custom_flatten: templates/terraform/custom_flatten/eventarc_channel_name.go.tmpl
73+
- name: uid
74+
type: String
75+
description: Server assigned unique identifier for the channel. The value is a UUID4 string and guaranteed to remain unchanged until the resource is deleted.
76+
output: true
77+
- name: createTime
78+
type: String
79+
description: The creation time.
80+
output: true
81+
- name: updateTime
82+
type: String
83+
description: The last-modified time.
84+
output: true
85+
- name: thirdPartyProvider
86+
type: String
87+
api_name: provider
88+
description: 'The name of the event provider (e.g. Eventarc SaaS partner) associated with the channel. This provider will be granted permissions to publish events to the channel. Format: `projects/{project}/locations/{location}/providers/{provider_id}`.'
89+
immutable: true
90+
- name: pubsubTopic
91+
type: String
92+
description: 'The name of the Pub/Sub topic created and managed by Eventarc system as a transport for the event delivery. Format: `projects/{project}/topics/{topic_id}`.'
93+
output: true
94+
- name: state
95+
type: Enum
96+
description: The state of a Channel.
97+
output: true
98+
enum_values:
99+
- STATE_UNSPECIFIED
100+
- PENDING
101+
- ACTIVE
102+
- INACTIVE
103+
- name: activationToken
104+
type: String
105+
description: The activation token for the channel. The token must be used by the provider to register the channel for publishing.
106+
output: true
107+
- name: cryptoKeyName
108+
type: String
109+
diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName
110+
description: Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt their event data. It must match the pattern `projects/*/locations/*/keyRings/*/cryptoKeys/*`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2025 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
14+
return expandToRegionalLongForm("projects/%s/locations/%s/channels/%s", v, d, config)
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2025 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
14+
return d.Get("name")
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "google_eventarc_channel" "{{$.PrimaryResourceId}}" {
2+
location = "us-central1"
3+
name = "{{index $.Vars "channel_name"}}"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "google_eventarc_channel" "{{$.PrimaryResourceId}}" {
2+
location = "us-central1"
3+
name = "{{index $.Vars "channel_name"}}"
4+
crypto_key_name = "{{index $.Vars "key_name"}}"
5+
third_party_provider = "projects/{{index $.TestEnvVars "project"}}/locations/us-central1/providers/datadog"
6+
}

mmv1/third_party/terraform/services/eventarc/resource_eventarc_channel_meta.yaml

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package eventarc_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-provider-google/google/acctest"
7+
"github.com/hashicorp/terraform-provider-google/google/envvar"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
)
11+
12+
func TestAccEventarcChannel_cryptoKeyUpdate(t *testing.T) {
13+
t.Parallel()
14+
15+
region := envvar.GetTestRegionFromEnv()
16+
context := map[string]interface{}{
17+
"region": region,
18+
"project_name": envvar.GetTestProjectFromEnv(),
19+
"project_number": envvar.GetTestProjectNumberFromEnv(),
20+
"key1": acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", region, "tf-bootstrap-eventarc-channel-key1").CryptoKey.Name,
21+
"key2": acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", region, "tf-bootstrap-eventarc-channel-key2").CryptoKey.Name,
22+
"random_suffix": acctest.RandString(t, 10),
23+
}
24+
acctest.BootstrapIamMembers(t, []acctest.IamMember{
25+
{
26+
Member: "serviceAccount:service-{project_number}@gcp-sa-eventarc.iam.gserviceaccount.com",
27+
Role: "roles/cloudkms.cryptoKeyEncrypterDecrypter",
28+
},
29+
})
30+
31+
acctest.VcrTest(t, resource.TestCase{
32+
PreCheck: func() { acctest.AccTestPreCheck(t) },
33+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
34+
CheckDestroy: testAccCheckEventarcChannelDestroyProducer(t),
35+
Steps: []resource.TestStep{
36+
{
37+
Config: testAccEventarcChannel_setCryptoKey(context),
38+
},
39+
{
40+
ResourceName: "google_eventarc_channel.primary",
41+
ImportState: true,
42+
ImportStateVerify: true,
43+
},
44+
{
45+
Config: testAccEventarcChannel_cryptoKeyUpdate(context),
46+
},
47+
{
48+
ResourceName: "google_eventarc_channel.primary",
49+
ImportState: true,
50+
ImportStateVerify: true,
51+
},
52+
},
53+
})
54+
}
55+
56+
func testAccEventarcChannel_setCryptoKey(context map[string]interface{}) string {
57+
return acctest.Nprintf(`
58+
resource "google_eventarc_channel" "primary" {
59+
location = "%{region}"
60+
name = "tf-test-name%{random_suffix}"
61+
crypto_key_name = "%{key1}"
62+
third_party_provider = "projects/%{project_name}/locations/%{region}/providers/datadog"
63+
}
64+
`, context)
65+
}
66+
67+
func testAccEventarcChannel_cryptoKeyUpdate(context map[string]interface{}) string {
68+
return acctest.Nprintf(`
69+
resource "google_eventarc_channel" "primary" {
70+
location = "%{region}"
71+
name = "tf-test-name%{random_suffix}"
72+
crypto_key_name = "%{key2}"
73+
third_party_provider = "projects/%{project_name}/locations/%{region}/providers/datadog"
74+
}
75+
`, context)
76+
}
77+
78+
func TestAccEventarcChannel_longForm(t *testing.T) {
79+
t.Parallel()
80+
81+
context := map[string]interface{}{
82+
"region": envvar.GetTestRegionFromEnv(),
83+
"project_name": envvar.GetTestProjectFromEnv(),
84+
"random_suffix": acctest.RandString(t, 10),
85+
}
86+
87+
acctest.VcrTest(t, resource.TestCase{
88+
PreCheck: func() { acctest.AccTestPreCheck(t) },
89+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
90+
CheckDestroy: testAccCheckEventarcChannelDestroyProducer(t),
91+
Steps: []resource.TestStep{
92+
{
93+
Config: testAccEventarcChannel_longForm(context),
94+
},
95+
{
96+
ResourceName: "google_eventarc_channel.primary",
97+
ImportState: true,
98+
ImportStateVerify: true,
99+
ImportStateVerifyIgnore: []string{"name", "location", "project"},
100+
},
101+
},
102+
})
103+
}
104+
105+
func testAccEventarcChannel_longForm(context map[string]interface{}) string {
106+
return acctest.Nprintf(`
107+
resource "google_eventarc_channel" "primary" {
108+
location = "long/form/%{region}"
109+
project = "projects/%{project_name}"
110+
name = "projects/%{project_name}/locations/%{region}/channels/tf-test-name%{random_suffix}"
111+
third_party_provider = "projects/%{project_name}/locations/%{region}/providers/datadog"
112+
}
113+
`, context)
114+
}

0 commit comments

Comments
 (0)