-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pubsubConfigs to cloud source repository
- Loading branch information
Showing
5 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
templates/terraform/examples/sourcerepo_repository_full.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "google_service_account" "test-account" { | ||
account_id = "my-service-account" | ||
display_name = "Test Service Account" | ||
} | ||
|
||
resource "google_pubsub_topic" "topic" { | ||
name = "my-topic" | ||
} | ||
|
||
resource "google_sourcerepo_repository" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['repository_name'] %>" | ||
pubsub_configs { | ||
topic = google_pubsub_topic.topic.id | ||
message_format = "JSON" | ||
service_account_email = google_service_account.test-account.email | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
templates/terraform/post_create/source_repo_repository_update.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if v, ok := d.GetOkExists("pubsub_configs"); !isEmptyValue(reflect.ValueOf(pubsubConfigsProp)) && (ok || !reflect.DeepEqual(v, pubsubConfigsProp)) { | ||
log.Printf("[DEBUG] Calling update after create to patch in pubsub_configs") | ||
// pubsub_configs cannot be added on create | ||
return resourceSourceRepoRepositoryUpdate(d, meta) | ||
} |
28 changes: 28 additions & 0 deletions
28
templates/terraform/update_encoder/source_repo_repository.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2019 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. | ||
-%> | ||
// Add "topic" field using pubsubConfig map key | ||
pubsubConfigsVal := obj["pubsubConfigs"] | ||
if pubsubConfigsVal != nil { | ||
pubsubConfigs := pubsubConfigsVal.(map[string]interface{}) | ||
for key := range pubsubConfigs { | ||
config := pubsubConfigs[key].(map[string]interface{}) | ||
config["topic"] = key | ||
} | ||
} | ||
|
||
// Nest request body in "repo" field | ||
newObj := make(map[string]interface{}) | ||
newObj["repo"] = obj | ||
return newObj, nil |