Skip to content

Commit

Permalink
Merge pull request #3040 from hashicorp/remote-state-atlas
Browse files Browse the repository at this point in the history
Atlas environment information sent with remote state
  • Loading branch information
pearkes committed Sep 15, 2015
2 parents 30c2736 + eba638d commit 28ea44b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions state/remote/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func atlasFactory(conf map[string]string) (Client, error) {
return nil, fmt.Errorf("malformed name '%s', expected format '<account>/<name>'", 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
Expand All @@ -67,6 +72,7 @@ type AtlasClient struct {
User string
Name string
AccessToken string
RunId string
}

func (c *AtlasClient) Get() (*Payload, error) {
Expand Down Expand Up @@ -143,15 +149,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 {
Expand Down Expand Up @@ -227,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(),
}
}

0 comments on commit 28ea44b

Please sign in to comment.