From 91abe9372052a6fd7a60827328ebf4c63eb7a4df Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Tue, 26 Mar 2019 23:15:48 +0000 Subject: [PATCH] [WIP]: Add custom endpoints to Compute handwritten resources Signed-off-by: Modular Magician --- google/config.go | 5 +++++ google/provider.go | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/google/config.go b/google/config.go index 78a62681dc2..4101999230c 100644 --- a/google/config.go +++ b/google/config.go @@ -59,6 +59,9 @@ type Config struct { client *http.Client userAgent string + ComputeCustomEndpoint string + ComputeBetaCustomEndpoint string + tokenSource oauth2.TokenSource clientBilling *cloudbilling.APIService @@ -134,6 +137,7 @@ func (c *Config) LoadAndValidate() error { return err } c.clientCompute.UserAgent = userAgent + c.clientCompute.BasePath = c.ComputeCustomEndpoint log.Printf("[INFO] Instantiating GCE Beta client...") c.clientComputeBeta, err = computeBeta.New(client) @@ -141,6 +145,7 @@ func (c *Config) LoadAndValidate() error { return err } c.clientComputeBeta.UserAgent = userAgent + c.clientComputeBeta.BasePath = c.ComputeBetaCustomEndpoint log.Printf("[INFO] Instantiating GKE client...") c.clientContainer, err = container.New(client) diff --git a/google/provider.go b/google/provider.go index 4f5dfa02c75..aaa81e34ead 100644 --- a/google/provider.go +++ b/google/provider.go @@ -69,11 +69,28 @@ func Provider() terraform.ResourceProvider { "CLOUDSDK_COMPUTE_ZONE", }, nil), }, + "scopes": { Type: schema.TypeList, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "compute_custom_endpoint": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "GOOGLE_COMPUTE_CUSTOM_ENDPOINT", + }, nil), + }, + + "compute_beta_custom_endpoint": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "GOOGLE_COMPUTE_BETA_CUSTOM_ENDPOINT", + }, nil), + }, }, DataSourcesMap: map[string]*schema.Resource{ @@ -286,6 +303,15 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { config.Scopes[i] = scope.(string) } + // Add custom endpoints + if v, ok := d.GetOk("compute_custom_endpoint"); ok { + config.ComputeCustomEndpoint = v.(string) + } + + if v, ok := d.GetOk("compute_beta_custom_endpoint"); ok { + config.ComputeBetaCustomEndpoint = v.(string) + } + if err := config.LoadAndValidate(); err != nil { return nil, err }