Skip to content

Commit

Permalink
Allow overriding the base path for a URL with custom endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
rileykarson authored and modular-magician committed Jun 13, 2019
1 parent 7f8f824 commit 48d70a3
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 69 deletions.
8 changes: 4 additions & 4 deletions google/compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func expandComputeForwardingRuleBackendService(v interface{}, d TerraformResourc
return "https://www.googleapis.com/compute/v1/" + v.(string), nil
} else if strings.HasPrefix(v.(string), "regions/") || strings.HasPrefix(v.(string), "zones/") {
// For regional or zonal resources which include their region or zone, just put the project in front.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/")
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/")
if err != nil {
return nil, err
}
Expand All @@ -179,7 +179,7 @@ func expandComputeForwardingRuleBackendService(v interface{}, d TerraformResourc
// Anything else is assumed to be a regional resource, with a partial link that begins with the resource name.
// This isn't very likely - it's a last-ditch effort to extract something useful here. We can do a better job
// as soon as MultiResourceRefs are working since we'll know the types that this field is supposed to point to.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/")
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func expandComputeForwardingRuleTarget(v interface{}, d TerraformResourceData, c
return "https://www.googleapis.com/compute/v1/" + v.(string), nil
} else if strings.HasPrefix(v.(string), "regions/") || strings.HasPrefix(v.(string), "zones/") {
// For regional or zonal resources which include their region or zone, just put the project in front.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/")
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/")
if err != nil {
return nil, err
}
Expand All @@ -244,7 +244,7 @@ func expandComputeForwardingRuleTarget(v interface{}, d TerraformResourceData, c
// Anything else is assumed to be a regional resource, with a partial link that begins with the resource name.
// This isn't very likely - it's a last-ditch effort to extract something useful here. We can do a better job
// as soon as MultiResourceRefs are working since we'll know the types that this field is supposed to point to.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/")
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/")
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions google/compute_target_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func expandComputeTargetInstanceInstance(v interface{}, d TerraformResourceData,
return "https://www.googleapis.com/compute/v1/" + v.(string), nil
} else if strings.HasPrefix(v.(string), "regions/") || strings.HasPrefix(v.(string), "zones/") {
// For regional or zonal resources which include their region or zone, just put the project in front.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/")
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/")
if err != nil {
return nil, err
}
Expand All @@ -107,7 +107,7 @@ func expandComputeTargetInstanceInstance(v interface{}, d TerraformResourceData,
// Anything else is assumed to be a regional resource, with a partial link that begins with the resource name.
// This isn't very likely - it's a last-ditch effort to extract something useful here. We can do a better job
// as soon as MultiResourceRefs are working since we'll know the types that this field is supposed to point to.
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/")
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/")
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 48d70a3

Please sign in to comment.