@@ -3,6 +3,7 @@ package remote
3
3
import (
4
4
"bytes"
5
5
"crypto/md5"
6
+ "crypto/tls"
6
7
"encoding/base64"
7
8
"fmt"
8
9
"io"
@@ -13,7 +14,9 @@ import (
13
14
"path"
14
15
"strings"
15
16
17
+ "github.com/hashicorp/go-cleanhttp"
16
18
"github.com/hashicorp/go-retryablehttp"
19
+ "github.com/hashicorp/go-rootcerts"
17
20
"github.com/hashicorp/terraform/terraform"
18
21
)
19
22
@@ -90,7 +93,10 @@ func (c *AtlasClient) Get() (*Payload, error) {
90
93
}
91
94
92
95
// Request the url
93
- client := c .http ()
96
+ client , err := c .http ()
97
+ if err != nil {
98
+ return nil , err
99
+ }
94
100
resp , err := client .Do (req )
95
101
if err != nil {
96
102
return nil , err
@@ -169,7 +175,10 @@ func (c *AtlasClient) Put(state []byte) error {
169
175
req .ContentLength = int64 (len (state ))
170
176
171
177
// Make the request
172
- client := c .http ()
178
+ client , err := c .http ()
179
+ if err != nil {
180
+ return err
181
+ }
173
182
resp , err := client .Do (req )
174
183
if err != nil {
175
184
return fmt .Errorf ("Failed to upload state: %v" , err )
@@ -197,7 +206,10 @@ func (c *AtlasClient) Delete() error {
197
206
}
198
207
199
208
// Make the request
200
- client := c .http ()
209
+ client , err := c .http ()
210
+ if err != nil {
211
+ return err
212
+ }
201
213
resp , err := client .Do (req )
202
214
if err != nil {
203
215
return fmt .Errorf ("Failed to delete state: %v" , err )
@@ -247,11 +259,23 @@ func (c *AtlasClient) url() *url.URL {
247
259
}
248
260
}
249
261
250
- func (c * AtlasClient ) http () * retryablehttp.Client {
262
+ func (c * AtlasClient ) http () ( * retryablehttp.Client , error ) {
251
263
if c .HTTPClient != nil {
252
- return c .HTTPClient
264
+ return c .HTTPClient , nil
265
+ }
266
+ tlsConfig := & tls.Config {}
267
+ err := rootcerts .ConfigureTLS (tlsConfig , & rootcerts.Config {
268
+ CAFile : os .Getenv ("ATLAS_CAFILE" ),
269
+ CAPath : os .Getenv ("ATLAS_CAPATH" ),
270
+ })
271
+ if err != nil {
272
+ return nil , err
253
273
}
254
- return retryablehttp .NewClient ()
274
+ rc := retryablehttp .NewClient ()
275
+ t := cleanhttp .DefaultTransport ()
276
+ t .TLSClientConfig = tlsConfig
277
+ rc .HTTPClient .Transport = t
278
+ return rc , nil
255
279
}
256
280
257
281
// Atlas returns an HTTP 409 - Conflict if the pushed state reports the same
0 commit comments