Skip to content

Commit

Permalink
Merge pull request #95 from terraform-providers/svh/f-ssl-skip-verify
Browse files Browse the repository at this point in the history
Add an option to skip certificate verifications
  • Loading branch information
koikonom authored Oct 8, 2020
2 parents 3333bea + 4b38b3d commit c7ee8d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 24 additions & 3 deletions tfe/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package tfe

import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"sort"
Expand Down Expand Up @@ -59,6 +61,13 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["token"],
DefaultFunc: schema.EnvDefaultFunc("TFE_TOKEN", nil),
},

"ssl_skip_verify": {
Type: schema.TypeBool,
Optional: true,
Description: descriptions["ssl_skip_verify"],
DefaultFunc: schema.EnvDefaultFunc("TFE_SSL_SKIP_VERIFY", false),
},
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -106,14 +115,25 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

providerUaString := fmt.Sprintf("terraform-provider-tfe/%s", providerVersion.ProviderVersion)

httpClient := tfe.DefaultConfig().HTTPClient

// Make sure the transport has a TLS config.
transport := httpClient.Transport.(*http.Transport)
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{}
}

// Configure the certificate verification options.
transport.TLSClientConfig.InsecureSkipVerify = d.Get("ssl_skip_verify").(bool)

// Get the Terraform CLI configuration.
config := cliConfig()

// Create a new credential source and service discovery object.
credsSrc := credentialsSource(config)
services := disco.NewWithCredentialsSource(credsSrc)
services.SetUserAgent(providerUaString)
services.Transport = logging.NewTransport("TFE Discovery", services.Transport)
services.Transport = logging.NewTransport("TFE Discovery", transport)

// Add any static host configurations service discovery object.
for userHost, hostConfig := range config.Hosts {
Expand Down Expand Up @@ -190,8 +210,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return nil, fmt.Errorf("required token could not be found")
}

httpClient := tfe.DefaultConfig().HTTPClient
httpClient.Transport = logging.NewTransport("TFE", httpClient.Transport)
// Wrap the configured transport to enable logging.
httpClient.Transport = logging.NewTransport("TFE", transport)

// Create a new TFE client config
cfg := &tfe.Config{
Expand Down Expand Up @@ -378,4 +398,5 @@ var descriptions = map[string]string{
"hostname": "The Terraform Enterprise hostname to connect to. Defaults to app.terraform.io.",
"token": "The token used to authenticate with Terraform Enterprise. We recommend omitting\n" +
"the token which can be set as credentials in the CLI config file.",
"ssl_skip_verify": "Whether or not to skip certificate verifications.",
}
3 changes: 3 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ The following arguments are supported:
in the [CLI config file](/docs/commands/cli-config.html#credentials) or set
the `TFE_TOKEN` environment variable. See [Authentication](#authentication)
above for more.
* `ssl_skip_verify` - (Optional) Whether or not to skip certificate verifications.
Defaults to `false`. Can be overridden setting the `TFE_SSL_SKIP_VERIFY`
environment variable.

0 comments on commit c7ee8d3

Please sign in to comment.