mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 15:52:39 +00:00
Retrieve current OAuth access token from google_client_config data source (#1277)
* Added access_token field to google_client_config data source * Refined documentation of google_client_config
This commit is contained in:
parent
b3a1f43dbc
commit
3460ddcaa7
|
@ -52,6 +52,8 @@ type Config struct {
|
|||
client *http.Client
|
||||
userAgent string
|
||||
|
||||
tokenSource oauth2.TokenSource
|
||||
|
||||
clientBilling *cloudbilling.Service
|
||||
clientCompute *compute.Service
|
||||
clientComputeBeta *computeBeta.Service
|
||||
|
@ -135,6 +137,8 @@ func (c *Config) loadAndValidate() error {
|
|||
}
|
||||
}
|
||||
|
||||
c.tokenSource = tokenSource
|
||||
|
||||
client.Transport = logging.NewTransport("Google", client.Transport)
|
||||
|
||||
versionString := terraform.VersionString()
|
||||
|
|
|
@ -19,6 +19,12 @@ func dataSourceGoogleClientConfig() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"access_token": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Sensitive: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -30,5 +36,11 @@ func dataSourceClientConfigRead(d *schema.ResourceData, meta interface{}) error
|
|||
d.Set("project", config.Project)
|
||||
d.Set("region", config.Region)
|
||||
|
||||
token, err := config.tokenSource.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("access_token", token.AccessToken)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ func TestAccDataSourceGoogleClientConfig_basic(t *testing.T) {
|
|||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet(resourceName, "project"),
|
||||
resource.TestCheckResourceAttrSet(resourceName, "region"),
|
||||
resource.TestCheckResourceAttrSet(resourceName, "access_token"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,6 +20,25 @@ output "project" {
|
|||
}
|
||||
```
|
||||
|
||||
## Example Usage: Configure Kubernetes provider with OAuth2 access token
|
||||
|
||||
```tf
|
||||
data "google_client_config" "default" {}
|
||||
|
||||
data "google_container_cluster" "my_cluster" {
|
||||
name = "my-cluster"
|
||||
zone = "us-east1-a"
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
load_config_file = false
|
||||
|
||||
host = "https://${google_container_cluster.my_cluster.endpoint}"
|
||||
token = "${data.google_client_config.default.access_token}"
|
||||
cluster_ca_certificate = "${base64decode(google_container_cluster.my_cluster.master_auth.0.cluster_ca_certificate)}"
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
There are no arguments available for this data source.
|
||||
|
@ -31,3 +50,5 @@ In addition to the arguments listed above, the following attributes are exported
|
|||
* `project` - The ID of the project to apply any resources to.
|
||||
|
||||
* `region` - The region to operate under.
|
||||
|
||||
* `access_token` - The OAuth2 access token used by the client to authenticate against the Google Cloud API.
|
||||
|
|
Loading…
Reference in New Issue
Block a user