From d19ec9d57a221a290f4c1b8853699a419548dd49 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Thu, 20 Aug 2015 13:21:47 -0700 Subject: [PATCH 1/2] remote/atlas: remove old force param commented out It appears this was left in through development, but as force is not a parameter likely doesn't have any relevance anymore. --- state/remote/atlas.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/state/remote/atlas.go b/state/remote/atlas.go index 264cf6a52..116d88372 100644 --- a/state/remote/atlas.go +++ b/state/remote/atlas.go @@ -143,15 +143,6 @@ func (c *AtlasClient) Put(state []byte) error { hash := md5.Sum(state) b64 := base64.StdEncoding.EncodeToString(hash[:]) - /* - // Set the force query parameter if needed - if force { - values := base.Query() - values.Set("force", "true") - base.RawQuery = values.Encode() - } - */ - // Make the HTTP client and request req, err := http.NewRequest("PUT", base.String(), bytes.NewReader(state)) if err != nil { From eba638d0446ea56387ea0f5575e5efa96ccdae31 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Thu, 20 Aug 2015 13:49:51 -0700 Subject: [PATCH 2/2] remote/atlas: if `ATLAS_RUN_ID` is set, send it with remote state save This detects the presence of ATLAS_RUN_ID in the environment and sends it if exists with remote state PUT requests with query params. --- state/remote/atlas.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/state/remote/atlas.go b/state/remote/atlas.go index 116d88372..f52d834a2 100644 --- a/state/remote/atlas.go +++ b/state/remote/atlas.go @@ -51,6 +51,11 @@ func atlasFactory(conf map[string]string) (Client, error) { return nil, fmt.Errorf("malformed name '%s', expected format '/'", name) } + // If it exists, add the `ATLAS_RUN_ID` environment + // variable as a param, which is injected during Atlas Terraform + // runs. This is completely optional. + client.RunId = os.Getenv("ATLAS_RUN_ID") + client.Server = server client.ServerURL = url client.AccessToken = token @@ -67,6 +72,7 @@ type AtlasClient struct { User string Name string AccessToken string + RunId string } func (c *AtlasClient) Get() (*Payload, error) { @@ -218,10 +224,15 @@ func (c *AtlasClient) readBody(b io.Reader) string { } func (c *AtlasClient) url() *url.URL { + values := url.Values{} + + values.Add("atlas_run_id", c.RunId) + values.Add("access_token", c.AccessToken) + return &url.URL{ Scheme: c.ServerURL.Scheme, Host: c.ServerURL.Host, Path: path.Join("api/v1/terraform/state", c.User, c.Name), - RawQuery: fmt.Sprintf("access_token=%s", c.AccessToken), + RawQuery: values.Encode(), } }