Skip to content

Commit

Permalink
google_app_engine_service_split_traffic resource (#2269)
Browse files Browse the repository at this point in the history
* Appengine Service resource

* Added custom_create in custom_code.
* Added appengine service resource

* Updates based on review

* Updates based on review

* update based on review

* Updates

* Update

* Update

* Updated the example

* Updated the example and website link

* Skip Delete on test and noop

* Rebased and merged the appengine terraform.yaml

* Updates

* Fixes

* updated the example and excluded split from reading

* updated the example

* Reverted custom_create related code

* Reverted resource.erb

* updates

* removed the error check

* Updates

* Fixes

* Fixed the import in test script

* Updates as per review

* chanded the operation to OpAsync

* Updated the Objects from Async to OpAsync

* Fixed the example primary resource name

* Testing by removing id_format and import_format

* reverted import and id format and also the example

* Fixed the id_format

* Updates based on review

* Typo fix

* Changed url_param_only to api_name

* Updated the resource.erb from upstream/master
  • Loading branch information
khanali21 committed Feb 20, 2020
1 parent da6931d commit a9cabe8
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 1 deletion.
2 changes: 2 additions & 0 deletions products/appengine/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- priority
Service: !ruby/object:Overrides::Ansible::ResourceOverride
exclude: true
ServiceSplitTraffic: !ruby/object:Overrides::Ansible::ResourceOverride
exclude: true
StandardAppVersion: !ruby/object:Overrides::Ansible::ResourceOverride
exclude: true
DomainMapping: !ruby/object:Overrides::Ansible::ResourceOverride
Expand Down
65 changes: 65 additions & 0 deletions products/appengine/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,69 @@ objects:
Pathname within the host. Must start with a "/". A single "*" can be included at the end of the path.
The sum of the lengths of the domain and path may not exceed 100 characters.
required: true
- !ruby/object:Api::Resource
name: 'ServiceSplitTraffic'
description: |
Traffic routing configuration for versions within a single service. Traffic splits define how traffic directed to the service is assigned to versions.
base_url: 'apps/{{project}}/services'
self_link: 'apps/{{project}}/services/{{service}}'
create_url: 'apps/{{project}}/services/{{service}}?migrateTraffic={{migrate_traffic}}&updateMask=split'
create_verb: :PATCH
update_url: 'apps/{{project}}/services/{{service}}?migrateTraffic={{migrate_traffic}}'
update_verb: :PATCH
update_mask: true
references: !ruby/object:Api::Resource::ReferenceLinks
api: 'https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services'
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
kind: 'appengine#operation'
path: 'name'
base_url: 'projects/{{project}}/global/operations/{{op_id}}'
wait_ms: 1000
result: !ruby/object:Api::OpAsync::Result
path: 'targetLink'
status: !ruby/object:Api::OpAsync::Status
path: 'status'
complete: 'DONE'
allowed:
- 'PENDING'
- 'RUNNING'
- 'DONE'
error: !ruby/object:Api::OpAsync::Error
path: 'error/errors'
message: 'message'
parameters:
- !ruby/object:Api::Type::Boolean
name: 'migrate_traffic'
url_param_only: true
description: |
If set to true traffic will be migrated to this version.
properties:
- !ruby/object:Api::Type::String
name: 'service'
api_name: 'id'
required: true
description: |
The name of the service these settings apply to.
- !ruby/object:Api::Type::NestedObject
name: 'split'
description: |
Mapping that defines fractional HTTP traffic diversion to different versions within the service.
required: true
properties:
- !ruby/object:Api::Type::Enum
name: 'shardBy'
description: |
Mechanism used to determine which version a request is sent to. The traffic selection algorithm will be stable for either type until allocations are changed.
values:
- :UNSPECIFIED
- :COOKIE
- :IP
- :RANDOM
- !ruby/object:Api::Type::KeyValuePairs
name: 'allocations'
required: true
description: |
Mapping from version IDs within the service to fractional (0.000, 1] allocations of traffic for that version. Each version can be specified only once, but some versions in the service may not have any traffic allocation. Services that have traffic allocated cannot be deleted until either the service is deleted or their traffic allocation is removed. Allocations must sum to 1. Up to two decimal place precision is supported for IP-based splits and up to three decimal places is supported for cookie-based splits.
2 changes: 2 additions & 0 deletions products/appengine/inspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
exclude: true
Service: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true
ServiceSplitTraffic: !ruby/object:Overrides::Inspec::ResourceOverride
exclude: true

23 changes: 22 additions & 1 deletion products/appengine/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,28 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_id: "web_service"
vars:
bucket_name: "appengine-test-bucket"

ServiceSplitTraffic: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "apps/{{project}}/services/{{service}}"
import_format: ["apps/{{project}}/services/{{service}}"]
mutex: "apps/{{project}}"
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_delete: templates/terraform/custom_delete/skip_delete.go.erb
test_check_destroy: templates/terraform/custom_check_destroy/skip_delete_during_test.go.erb
properties:
split: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
split.allocations: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: templates/terraform/custom_flatten/float64_to_string.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
name: "app_engine_service_split_traffic"
primary_resource_id: 'myapp'
vars:
service_id: "default"
split.allocations.v1: "1"
bucket_name: "appengine-static-content"
test_env_vars:
org_id: :ORG_ID
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log.Printf("[DEBUG] Ignoring destroy during test")
9 changes: 9 additions & 0 deletions templates/terraform/custom_flatten/float64_to_string.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData) interface{} {
transformed := make(map[string]string)
data := v.(map[string]interface{})
for key := range data {
transformed[key] = fmt.Sprintf("%f", data[key])
}
log.Printf("transformed = %#v", transformed)
return transformed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
resource "google_storage_bucket" "bucket" {
name = "<%= ctx[:vars]['bucket_name'] %>"
}

resource "google_storage_bucket_object" "object" {
name = "hello-world.zip"
bucket = "${google_storage_bucket.bucket.name}"
source = "./test-fixtures/appengine/hello-world.zip"
}

resource "google_app_engine_standard_app_version" "myapp_v1" {
version_id = "v1"
service = "myapp"
runtime = "nodejs10"
noop_on_destroy = true
entrypoint {
shell = "node ./app.js"
}
deployment {
zip {
source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/hello-world.zip"
}
}
env_variables = {
port = "8080"
}
depends_on = ["google_storage_bucket_object.object"]

}
resource "google_app_engine_standard_app_version" "myapp_v2" {
version_id = "v2"
service = "myapp"
runtime = "nodejs10"
entrypoint {
shell = "node ./app.js"
}
deployment {
zip {
source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/hello-world.zip"
}
}
env_variables = {
port = "8080"
}
depends_on = ["google_app_engine_standard_app_version.myapp_v1"]
}

resource "google_app_engine_service_split_traffic" "myapp" {
service = "${google_app_engine_standard_app_version.myapp_v2.service}"
migrate_traffic = false
split {
shard_by = "IP"
allocations = {
v1 = 0.75
v2 = 0.25
}
}
depends_on = ["google_app_engine_standard_app_version.myapp_v2"]
}


resource "google_app_engine_service_split_traffic" "myapp2" {
service = "${google_app_engine_standard_app_version.myapp_v2.service}"
migrate_traffic = false
split {
allocations = {
v1 = 1
}
}
depends_on = ["google_app_engine_service_split_traffic.myapp"]
}
2 changes: 2 additions & 0 deletions third_party/terraform/website-compiled/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@
</li>
<li<%%= sidebar_current("docs-google-app-engine-application-url-dispatch-rules") %>>
<a href="/docs/providers/google/r/app_engine_application_url_dispatch_rules.html">google_app_engine_application_url_dispatch_rules</a>
<li<%%= sidebar_current("docs-google-app-engine-service-split-traffic") %>>
<a href="/docs/providers/google/r/app_engine_service_split_traffic.html">google_app_engine_standard_app_version</a>
</li>
</ul>
</li>
Expand Down

0 comments on commit a9cabe8

Please sign in to comment.