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

Generate UrlMap in Terraform. #545

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3802,7 +3802,7 @@ objects:
- !ruby/object:Api::Type::String
name: 'description'
description: |
An optional description of this resource. Provide this property
An optional description of this HostRule. Provide this property
when you create the resource.
- !ruby/object:Api::Type::Array
name: 'hosts'
Expand Down Expand Up @@ -3869,6 +3869,7 @@ objects:
properties:
- !ruby/object:Api::Type::Array
name: 'paths'
required: true
item_type: Api::Type::String
description: |
The list of path patterns to match. Each must start with /
Expand All @@ -3887,7 +3888,7 @@ objects:
- !ruby/object:Api::Type::Array
name: 'tests'
description: |
The list of expected URL mappings. Request to update this UrlMap will
The list of expected URL mappings. Requests to update this UrlMap will
succeed only if all of the test cases pass.
item_type: !ruby/object:Api::Type::NestedObject
properties:
Expand Down
40 changes: 39 additions & 1 deletion products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,45 @@ overrides: !ruby/object:Provider::ResourceOverrides
tunnels: !ruby/object:Provider::Terraform::PropertyOverride
exclude: true
UrlMap: !ruby/object:Provider::Terraform::ResourceOverride
exclude: true
example:
- !ruby/object:Provider::Terraform::Examples
name: "url_map_basic"
primary_resource_id: "urlmap"
vars:
url_map_name: "urlmap"
login_backend_service_name: "login"
home_backend_service_name: "home"
http_health_check_name: "health-check"
backend_bucket_name: "static-asset-backend-bucket"
storage_bucket_name: "static-asset-bucket"
properties:
id: !ruby/object:Provider::Terraform::PropertyOverride
name: "map_id"
defaultService: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
description: The backend service or backend bucket to use when none of the given rules match.
hostRules: !ruby/object:Provider::Terraform::PropertyOverride
name: "host_rule"
is_set: true
hostRules.hosts: !ruby/object:Provider::Terraform::PropertyOverride
is_set: true
pathMatchers: !ruby/object:Provider::Terraform::PropertyOverride
name: "path_matcher"
pathMatchers.defaultService: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
description: The backend service or backend bucket to use when none of the given paths match.
pathMatchers.pathRules: !ruby/object:Provider::Terraform::PropertyOverride
name: "path_rule"
pathMatchers.pathRules.paths: !ruby/object:Provider::Terraform::PropertyOverride
is_set: true
pathMatchers.pathRules.service: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
description: The backend service or backend bucket to use if any of the given paths match.
tests.service: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/url_map_only_set_string.go.erb'
description: The backend service or backend bucket link that should be matched by this test.
tests: !ruby/object:Provider::Terraform::PropertyOverride
name: "test"
VpnTunnel: !ruby/object:Provider::Terraform::ResourceOverride
example:
- !ruby/object:Provider::Terraform::Examples
Expand Down
19 changes: 19 additions & 0 deletions templates/terraform/custom_expand/url_map_only_set_string.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%# The license inside this block applies to this file.
# Copyright 2017 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.
-%>
// ResourceRef only supports 1 type and UrlMap has references to a BackendBucket or BackendService. Just read the self_link string
// instead of extracting the name and making a self_link out of it.
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
73 changes: 73 additions & 0 deletions templates/terraform/examples/url_map_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
resource "google_compute_url_map" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['url_map_name'] %>"
description = "a description"

default_service = "${google_compute_backend_service.home.self_link}"

host_rule {
hosts = ["mysite.com"]
path_matcher = "allpaths"
}

path_matcher {
name = "allpaths"
default_service = "${google_compute_backend_service.home.self_link}"

path_rule {
paths = ["/home"]
service = "${google_compute_backend_service.home.self_link}"
}

path_rule {
paths = ["/login"]
service = "${google_compute_backend_service.login.self_link}"
}

path_rule {
paths = ["/static"]
service = "${google_compute_backend_bucket.static.self_link}"
}
}

test {
service = "${google_compute_backend_service.home.self_link}"
host = "hi.com"
path = "/home"
}
}

resource "google_compute_backend_service" "login" {
name = "<%= ctx[:vars]['login_backend_service_name'] %>"
port_name = "http"
protocol = "HTTP"
timeout_sec = 10

health_checks = ["${google_compute_http_health_check.default.self_link}"]
}

resource "google_compute_backend_service" "home" {
name = "<%= ctx[:vars]['home_backend_service_name'] %>"
port_name = "http"
protocol = "HTTP"
timeout_sec = 10

health_checks = ["${google_compute_http_health_check.default.self_link}"]
}

resource "google_compute_http_health_check" "default" {
name = "<%= ctx[:vars]['http_health_check_name'] %>"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}

resource "google_compute_backend_bucket" "static" {
name = "<%= ctx[:vars]['backend_bucket_name'] %>"
bucket_name = "${google_storage_bucket.static.name}"
enable_cdn = true
}

resource "google_storage_bucket" "static" {
name = "<%= ctx[:vars]['storage_bucket_name'] %>"
location = "US"
}
4 changes: 3 additions & 1 deletion templates/terraform/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ package google
<%
resource_name = product_ns + object.name
properties = object.all_user_properties
settable_properties = properties.reject(&:output).reject(&:url_param_only)
# Fingerprints aren't *really* settable properties, but they behave like one. At Create, they have no value but they
# can just be read in anyways, and after a Read they will need to be set in every Update.
settable_properties = properties.reject{ |v| v.output && !v.is_a?(Api::Type::Fingerprint) }.reject(&:url_param_only)
api_name_lower = String.new(product_ns)
api_name_lower[0] = api_name_lower[0].downcase
has_project = object.base_url.include?("{{project}}")
Expand Down