From eabc6b91237b5aae37072d41e9c897ff68c739ce Mon Sep 17 00:00:00 2001 From: Yu-Wei Huang Date: Wed, 6 Nov 2019 15:12:46 +0800 Subject: [PATCH 1/2] support custom API base URL depends on https://github.com/akshaykarle/go-mongodbatlas/pull/20 --- mongodbatlas/config.go | 3 ++- mongodbatlas/provider.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mongodbatlas/config.go b/mongodbatlas/config.go index c6d4bb36..60383c00 100644 --- a/mongodbatlas/config.go +++ b/mongodbatlas/config.go @@ -10,11 +10,12 @@ import ( type Config struct { AtlasUsername string AtlasAPIKey string + AtlasAPIURL string } func (c *Config) NewClient() *ma.Client { t := dac.NewTransport(c.AtlasUsername, c.AtlasAPIKey) httpClient := &http.Client{Transport: &t} - client := ma.NewClient(httpClient) + client := ma.NewCustomURLClient(httpClient, c.AtlasAPIURL) return client } diff --git a/mongodbatlas/provider.go b/mongodbatlas/provider.go index 7eefcbe7..66cbdb38 100644 --- a/mongodbatlas/provider.go +++ b/mongodbatlas/provider.go @@ -20,6 +20,12 @@ func Provider() terraform.ResourceProvider { DefaultFunc: schema.EnvDefaultFunc("MONGODB_ATLAS_API_KEY", ""), Description: "MongoDB Atlas API Key", }, + "api_url": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("MONGODB_ATLAS_API_URL", "https://cloud.mongodb.com/api/atlas/v1.0/"), + Description: "MongoDB Atlas API base url", + }, }, DataSourcesMap: map[string]*schema.Resource{ @@ -45,6 +51,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { config := Config{ AtlasUsername: d.Get("username").(string), AtlasAPIKey: d.Get("api_key").(string), + AtlasAPIURL: d.Get("api_url").(string), } client := config.NewClient() From db333f57264d9f4485a87529cc03bd5b45553681 Mon Sep 17 00:00:00 2001 From: Yu-Wei Huang Date: Wed, 6 Nov 2019 15:18:25 +0800 Subject: [PATCH 2/2] add document for `api_url` argument --- website/docs/index.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 0f37576f..63242907 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -82,3 +82,7 @@ Atlas `provider` block: * `username` - (Optional) This is the MongoDB Atlas username. It must be provided, but it can also be sourced from the `MONGODB_ATLAS_USERNAME` environment variable. + +* `api_url` - (Optional) This is the MongoDB API base URL. It can also be + sourced from the `MONGODB_ATLAS_API_URL` environment variable. Default + value is `https://cloud.mongodb.com/api/atlas/v1.0`.