# Copyright 2025 Google Inc.
# Licensed under the Apache License, Version 2.0 (the License);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
name: Channel
legacy_long_form_project: true
base_url: projects/{{project}}/locations/{{location}}/channels
create_url: projects/{{project}}/locations/{{location}}/channels?channelId={{name}}
self_link: projects/{{project}}/locations/{{location}}/channels/{{name}}
update_verb: PATCH
update_mask: true
references:
  guides:
    'Official Documentation': 'https://cloud.google.com/eventarc/standard/docs/third-parties/create-channels'
  api: https://cloud.google.com/eventarc/docs/reference/rest/v1/projects.locations.channels
async:
  actions: ['create', 'update', 'delete']
  type: OpAsync
  operation:
    base_url: '{{op_id}}'
  result:
    resource_inside_response: true
autogen_async: true
description: |
 The Eventarc Channel resource
error_retry_predicates:
  - transport_tpg.EventarcChannel403Retry
examples:
  - name: eventarc_channel_with_cmek
    primary_resource_id: primary
    bootstrap_iam:
      - member: "serviceAccount:service-{project_number}@gcp-sa-eventarc.iam.gserviceaccount.com"
        role: "roles/cloudkms.cryptoKeyEncrypterDecrypter"
    vars:
      channel_name: some-channel
      key_name: some-key
    test_env_vars:
      project: 'PROJECT_NAME'
      project_number: 'PROJECT_NUMBER'
    test_vars_overrides:
      'key_name': 'acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", "us-central1", "tf-bootstrap-eventarc-channel-key").CryptoKey.Name'
  - name: eventarc_channel
    primary_resource_id: primary
    vars:
      channel_name: some-channel
    exclude_docs: true
parameters:
  - name: location
    type: String
    description: The location for the resource
    url_param_only: true
    required: true
    immutable: true
properties:
  - name: name
    type: String
    description: The resource name of the channel. Must be unique within the location on the project.
    required: true
    immutable: true
    diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName
    custom_expand: templates/terraform/custom_expand/eventarc_channel_name.go.tmpl
    custom_flatten: templates/terraform/custom_flatten/eventarc_channel_name.go.tmpl
  - name: uid
    type: String
    description: Server assigned unique identifier for the channel. The value is a UUID4 string and guaranteed to remain unchanged until the resource is deleted.
    output: true
  - name: createTime
    type: String
    description: The creation time.
    output: true
  - name: updateTime
    type: String
    description: The last-modified time.
    output: true
  - name: thirdPartyProvider
    type: String
    api_name: provider
    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}`.'
    immutable: true
  - name: pubsubTopic
    type: String
    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}`.'
    output: true
  - name: state
    type: Enum
    description: The state of a Channel.
    output: true
    enum_values:
      - STATE_UNSPECIFIED
      - PENDING
      - ACTIVE
      - INACTIVE
  - name: activationToken
    type: String
    description: The activation token for the channel. The token must be used by the provider to register the channel for publishing.
    output: true
  - name: cryptoKeyName
    type: String
    diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName
    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/*`.
