Skip to content

Commit

Permalink
Terraform: Pubsub Topic labels update
Browse files Browse the repository at this point in the history
  • Loading branch information
drebes committed Jun 14, 2019
1 parent 772d0da commit fc0b5f5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
5 changes: 4 additions & 1 deletion products/pubsub/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ objects:
create_verb: :PUT
description: |
A named resource to which messages are sent by publishers.
input: true
iam_policy: !ruby/object:Api::Resource::IamPolicy
exclude: true
method_name_separator: ':'
Expand All @@ -40,10 +39,14 @@ objects:
name: 'name'
required: true
description: 'Name of the topic.'
input: true
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: |
A set of key/value label pairs to assign to this Topic.
update_verb: :PATCH
update_mask: true
update_url: projects/{{project}}/topics/{{name}}
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Managing Topics':
Expand Down
1 change: 1 addition & 0 deletions products/pubsub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/pubsub_noname.go.erb
update_encoder: templates/terraform/update_encoder/pubsub_topic.erb
Subscription: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "projects/{{project}}/subscriptions/{{name}}"
examples:
Expand Down
17 changes: 17 additions & 0 deletions templates/terraform/update_encoder/pubsub_topic.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# 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.
-%>
newObj := make(map[string]interface{})
newObj["topic"] = obj
return newObj, nil
52 changes: 52 additions & 0 deletions third_party/terraform/tests/resource_pubsub_topic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccPubsubTopic_update(t *testing.T) {
t.Parallel()

topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPubsubTopicDestroy,
Steps: []resource.TestStep{
{
Config: testAccPubsubTopic_update(topic, "foo", "bar"),
},
{
ResourceName: "google_pubsub_topic.foo",
ImportStateId: topic,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccPubsubTopic_update(topic, "wibble", "wobble"),
},
{
ResourceName: "google_pubsub_topic.foo",
ImportStateId: topic,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccPubsubTopic_update(topic, key, value string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"
labels = {
%s = "%s"
}
}
`, topic, key, value)
}

0 comments on commit fc0b5f5

Please sign in to comment.