Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CloudTasksQueue resource #2662

Merged
merged 2 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/ansible
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
8 changes: 6 additions & 2 deletions products/cloudtasks/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ objects:
- !ruby/object:Api::Resource
name: 'Queue'
base_url: projects/{{project}}/locations/{{location}}/queues
update_verb: :PATCH
update_mask: true
description: |
A named resource to which messages are sent by publishers.
parameters:
Expand All @@ -45,14 +47,16 @@ objects:
- !ruby/object:Api::Type::String
name: 'location'
required: true
input: true
description: The location of the queue
properties:
- !ruby/object:Api::Type::String
name: 'name'
input: true
description: The queue name.
pattern: projects/{{project}}/locations/{{location}}/queues/{{name}}
- !ruby/object:Api::Type::NestedObject
name: appEngineRoutingOverride
name: 'appEngineRoutingOverride'
description: |
Overrides for task-level appEngineRouting. These settings apply only
to App Engine tasks in this queue
Expand Down Expand Up @@ -133,7 +137,7 @@ objects:

-1 indicates unlimited attempts.
- !ruby/object:Api::Type::String
name: maxRetryDuration
name: 'maxRetryDuration'
description: |
If positive, maxRetryDuration specifies the time limit for
retrying a failed task, measured from when the task was first
Expand Down
63 changes: 63 additions & 0 deletions products/cloudtasks/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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.

--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Queue: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "projects/{{project}}/locations/{{location}}/queues/{{name}}"
parameters:
status: !ruby/object:Overrides::Terraform::PropertyOverride
output: true
properties:
appEngineRoutingOverride: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: templates/terraform/custom_flatten/cloudtasks_queue_appenginerouting.go.erb
location: !ruby/object:Overrides::Terraform::PropertyOverride
url_param_only: true
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
custom_expand: templates/terraform/custom_expand/qualify_queue_name.go.erb
rateLimits: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
rateLimits.maxConcurrentDispatches: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
rateLimits.maxDispatchesPerSecond: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
retryConfig: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
retryConfig.maxAttempts: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
tysen marked this conversation as resolved.
Show resolved Hide resolved
retryConfig.maxRetryDuration: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
retryConfig.minBackoff: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
retryConfig.maxBackoff: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
retryConfig.maxDoublings: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
retryConfig.purgeTime: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
status: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "queue_basic"
primary_resource_id: "default"
vars:
name: "cloud-tasks-queue-test"

# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
# This is usually to add licensing info, autogeneration notices, etc.
compile:
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%>
3 changes: 3 additions & 0 deletions templates/terraform/custom_expand/qualify_queue_name.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return replaceVars(d, config, "projects/{{project}}/locations/{{location}}/queues/{{name}}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%# 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.
-%>
// service, version, and instance are input-only. host is output-only.
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["host"] = original["host"]
if override, ok := d.GetOk("app_engine_routing_override"); ok && len(override.([]interface{})) > 0 {
transformed["service"] = d.Get("app_engine_routing_override.0.service")
transformed["version"] = d.Get("app_engine_routing_override.0.version")
transformed["instance"] = d.Get("app_engine_routing_override.0.instance")
}
return []interface{}{transformed}
}
4 changes: 4 additions & 0 deletions templates/terraform/examples/queue_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "google_cloud_tasks_queue" "default" {
name = "<%= ctx[:vars]['name'] %>"
location = "us-central1"
}
142 changes: 142 additions & 0 deletions third_party/terraform/tests/resource_cloud_tasks_queue_test.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<% autogen_exception -%>
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

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

name := "cloudtasksqueuetest-" + acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudTasksQueue_full(name),
},
{
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_engine_routing_override.0.service", "app_engine_routing_override.0.version", "app_engine_routing_override.0.instance"},
},
{
Config: testAccCloudTasksQueue_update(name),
},
{
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_engine_routing_override.0.service", "app_engine_routing_override.0.version", "app_engine_routing_override.0.instance"},
},
},
})
}

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

name := "cloudtasksqueuetest-" + acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudTasksQueue_full(name),
},
{
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_engine_routing_override.0.service", "app_engine_routing_override.0.version", "app_engine_routing_override.0.instance"},
},
{
Config: testAccCloudTasksQueue_basic(name),
},
{
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_engine_routing_override.0.service", "app_engine_routing_override.0.version", "app_engine_routing_override.0.instance"},
},
},
})
}

func testAccCloudTasksQueue_basic(name string) string {
return fmt.Sprintf(`
resource "google_cloud_tasks_queue" "default" {
name = "%s"
location = "us-central1"

retry_config {
max_attempts = 5
}

}
`, name)
}

func testAccCloudTasksQueue_full(name string) string {
return fmt.Sprintf(`
resource "google_cloud_tasks_queue" "default" {
name = "%s"
location = "us-central1"

app_engine_routing_override {
service = "worker"
version = "1.0"
instance = "test"
}

rate_limits {
max_concurrent_dispatches = 3
max_dispatches_per_second = 2
}

retry_config {
max_attempts = 5
max_retry_duration = "4s"
max_backoff = "3s"
min_backoff = "2s"
max_doublings = 1
}
}
`, name)
}

func testAccCloudTasksQueue_update(name string) string {
return fmt.Sprintf(`
resource "google_cloud_tasks_queue" "default" {
name = "%s"
location = "us-central1"

app_engine_routing_override {
service = "main"
version = "2.0"
instance = "beta"
}

rate_limits {
max_concurrent_dispatches = 4
max_dispatches_per_second = 3
}

retry_config {
max_attempts = 6
max_retry_duration = "5s"
max_backoff = "4s"
min_backoff = "3s"
tysen marked this conversation as resolved.
Show resolved Hide resolved
max_doublings = 2
}
}
`, name)
}