Skip to content

Commit

Permalink
Merge 5aec64d into c5b774b
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow committed Jun 5, 2018
2 parents c5b774b + 5aec64d commit 5914494
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/terraform
11 changes: 10 additions & 1 deletion products/redis/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ objects:
base_url: |
projects/{{project}}/locations/{{region}}/instances?instanceId={{name}}
self_link: projects/{{project}}/locations/{{region}}/instances/{{name}}
update_verb: :PATCH
description: |
A Google Cloud Redis instance.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/memorystore/docs/redis/'
api: 'https://cloud.google.com/memorystore/docs/redis/reference/rest/'
input: true # TODO(danawillow): support for updates
<%=
# Cloud Redis takes a fair bit of time to provision, try six minutes.
indent(compile_file({timeouts: { insert_sec: 6 * 60 }},
Expand All @@ -46,6 +46,7 @@ objects:
description: |
The name of the Redis region of the instance.
required: true
input: true
properties:
- !ruby/object:Api::Type::String
name: alternativeLocationId
Expand All @@ -54,12 +55,14 @@ objects:
against zonal failures by provisioning it across two zones.
If provided, it must be a different zone from the one provided in
[locationId].
input: true
- !ruby/object:Api::Type::String
name: authorizedNetwork
description: |
The full name of the Google Compute Engine network to which the
instance is connected. If left unspecified, the default network
will be used.
input: true
- !ruby/object:Api::Type::Time
name: createTime
description: |
Expand All @@ -75,6 +78,7 @@ objects:
instances, this can be either [locationId] or [alternativeLocationId]
and can change after a failover event.
output: true
input: true
- !ruby/object:Api::Type::String
name: displayName
description: |
Expand All @@ -98,11 +102,13 @@ objects:
instances will be created across two zones for protection against
zonal failures. If [alternativeLocationId] is also provided, it must
be different from [locationId].
input: true
- !ruby/object:Api::Type::String
name: name
description: |
The ID of the instance or a fully qualified identifier for the instance.
required: true
input: true
- !ruby/object:Api::Type::Integer
name: memorySizeGb
description: Redis memory size in GiB.
Expand All @@ -118,6 +124,7 @@ objects:
version will be used. Updating the version will perform an
upgrade/downgrade to the new version. Currently, the supported values
are REDIS_3_2 for Redis 3.2.
input: true
- !ruby/object:Api::Type::String
name: reservedIpRange
description: |
Expand All @@ -126,6 +133,7 @@ objects:
block, for example, 10.0.0.0/29 or 192.168.0.0/29. Ranges must be
unique and non-overlapping with existing subnets in an authorized
network.
input: true
- !ruby/object:Api::Type::Enum
name: tier
description: |
Expand All @@ -137,3 +145,4 @@ objects:
- :BASIC
- :STANDARD_HA
default_value: :BASIC
input: true
1 change: 1 addition & 0 deletions products/redis/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ overrides: !ruby/object:Provider::ResourceOverrides
custom_code: !ruby/object:Provider::Terraform::CustomCode
decoder: 'templates/terraform/decoders/redis_instance.erb'
encoder: 'templates/terraform/encoders/redis_instance.erb'
pre_update: 'templates/terraform/pre_update/redis_instance.erb'
examples: |
### Basic Usage
```hcl
Expand Down
16 changes: 16 additions & 0 deletions templates/terraform/pre_update/redis_instance.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
updateMask := []string{}
if d.HasChange("display_name") {
updateMask = append(updateMask, "displayName")
}
if d.HasChange("labels") {
updateMask = append(updateMask, "labels")
}
if d.HasChange("memory_size_gb") {
updateMask = append(updateMask, "memorySizeGb")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}
20 changes: 15 additions & 5 deletions templates/terraform/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,12 @@ func sendRequest(config *Config, method, rawurl string, body map[string]interfac
}
}

u, err := url.Parse(rawurl)
u, err := addQueryParams(rawurl, map[string]string{"alt": "json"})
if err != nil {
return nil, err
}
q := u.Query()
q.Set("alt", "json")
u.RawQuery = q.Encode()

req, err := http.NewRequest(method, u.String(), &buf)
req, err := http.NewRequest(method, u, &buf)
if err != nil {
return nil, err
}
Expand All @@ -136,6 +133,19 @@ func sendRequest(config *Config, method, rawurl string, body map[string]interfac
return result, nil
}

func addQueryParams(rawurl string, params map[string]string) (string, error) {
u, err := url.Parse(rawurl)
if err != nil {
return "", err
}
q := u.Query()
for k, v := range params {
q.Set(k, v)
}
u.RawQuery = q.Encode()
return u.String(), nil
}

func replaceVars(d TerraformResourceData, config *Config, linkTmpl string) (string, error) {
re := regexp.MustCompile("{{([[:word:]]+)}}")
var project, region, zone string
Expand Down

0 comments on commit 5914494

Please sign in to comment.