Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/google: OAuth2 support #3553

Merged
merged 1 commit into from
Oct 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions builtin/providers/google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type Config struct {

func (c *Config) loadAndValidate() error {
var account accountFile
clientScopes := []string{
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/cloud-platform",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle it should be possible to have only cloud-platform as all the others are meant to be subsumed by cloud-platform. When all PRs are in, you could try running the acceptance tests with just cloud-platform and see if it works.

"https://www.googleapis.com/auth/ndev.clouddns.readwrite",
"https://www.googleapis.com/auth/devstorage.full_control",
}


if c.AccountFile == "" {
c.AccountFile = os.Getenv("GOOGLE_ACCOUNT_FILE")
Expand Down Expand Up @@ -79,13 +86,6 @@ func (c *Config) loadAndValidate() error {
}
}

clientScopes := []string{
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/ndev.clouddns.readwrite",
"https://www.googleapis.com/auth/devstorage.full_control",
}

// Get the token for use in our requests
log.Printf("[INFO] Requesting Google token...")
log.Printf("[INFO] -- Email: %s", account.ClientEmail)
Expand All @@ -105,16 +105,12 @@ func (c *Config) loadAndValidate() error {
client = conf.Client(oauth2.NoContext)

} else {
log.Printf("[INFO] Requesting Google token via GCE Service Role...")
client = &http.Client{
Transport: &oauth2.Transport{
// Fetch from Google Compute Engine's metadata server to retrieve
// an access token for the provided account.
// If no account is specified, "default" is used.
Source: google.ComputeTokenSource(""),
},
log.Printf("[INFO] Authenticating using DefaultClient");
err := error(nil)
client, err = google.DefaultClient(oauth2.NoContext, clientScopes...)
if err != nil {
return err
}

}

// Build UserAgent
Expand Down
6 changes: 5 additions & 1 deletion builtin/providers/google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Provider() terraform.ResourceProvider {
Schema: map[string]*schema.Schema{
"account_file": &schema.Schema{
Type: schema.TypeString,
Required: true,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_ACCOUNT_FILE", nil),
ValidateFunc: validateAccountFile,
},
Expand Down Expand Up @@ -78,6 +78,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}

func validateAccountFile(v interface{}, k string) (warnings []string, errors []error) {
if v == nil {
return
}

value := v.(string)

if value == "" {
Expand Down