provider/azurerm: add client_config data source
azurerm_client_config provides access to: - client_id - tenant_id - subscription_id ``` TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMClientConfig -timeout 120m === RUN TestAccAzureRMClientConfig_basic --- PASS: TestAccAzureRMClientConfig_basic (27.79s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 27.862s ```
This commit is contained in:
parent
1a08318a45
commit
6374cc7d33
|
@ -24,6 +24,10 @@ import (
|
|||
// ArmClient contains the handles to all the specific Azure Resource Manager
|
||||
// resource classes' respective clients.
|
||||
type ArmClient struct {
|
||||
clientId string
|
||||
tenantId string
|
||||
subscriptionId string
|
||||
|
||||
rivieraClient *riviera.Client
|
||||
|
||||
availSetClient compute.AvailabilitySetsClient
|
||||
|
@ -110,7 +114,11 @@ func setUserAgent(client *autorest.Client) {
|
|||
// *ArmClient based on the Config's current settings.
|
||||
func (c *Config) getArmClient() (*ArmClient, error) {
|
||||
// client declarations:
|
||||
client := ArmClient{}
|
||||
client := ArmClient{
|
||||
clientId: c.ClientID,
|
||||
tenantId: c.TenantID,
|
||||
subscriptionId: c.SubscriptionID,
|
||||
}
|
||||
|
||||
rivieraClient, err := riviera.NewClient(&riviera.AzureResourceManagerCredentials{
|
||||
ClientID: c.ClientID,
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceArmClientConfig() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Read: dataSourceArmClientConfigRead,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"client_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tenant_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"subscription_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
|
||||
d.SetId(time.Now().UTC().String())
|
||||
d.Set("client_id", client.clientId)
|
||||
d.Set("tenant_id", client.tenantId)
|
||||
d.Set("subscription_id", client.subscriptionId)
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAzureRMClientConfig_basic(t *testing.T) {
|
||||
clientId := os.Getenv("ARM_CLIENT_ID")
|
||||
tenantId := os.Getenv("ARM_TENANT_ID")
|
||||
subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID")
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccCheckArmClientConfig_basic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAzureRMClientConfigAttr("data.azurerm_client_config.current", "client_id", clientId),
|
||||
testAzureRMClientConfigAttr("data.azurerm_client_config.current", "tenant_id", tenantId),
|
||||
testAzureRMClientConfigAttr("data.azurerm_client_config.current", "subscription_id", subscriptionId),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Wraps resource.TestCheckResourceAttr to prevent leaking values to console
|
||||
// in case of mismatch
|
||||
func testAzureRMClientConfigAttr(name, key, value string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
err := resource.TestCheckResourceAttr(name, key, value)(s)
|
||||
if err != nil {
|
||||
// return fmt.Errorf("%s: Attribute '%s', failed check (values hidden)", name, key)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
const testAccCheckArmClientConfig_basic = `
|
||||
data "azurerm_client_config" "current" { }
|
||||
`
|
|
@ -44,6 +44,10 @@ func Provider() terraform.ResourceProvider {
|
|||
},
|
||||
},
|
||||
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
"azurerm_client_config": dataSourceArmClientConfig(),
|
||||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
// These resources use the Azure ARM SDK
|
||||
"azurerm_availability_set": resourceArmAvailabilitySet(),
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
layout: "azurerm"
|
||||
page_title: "Azure Resource Manager: azurerm_client_config"
|
||||
sidebar_current: "docs-azurerm-datasource-client-config"
|
||||
description: |-
|
||||
Get information about the configuration of the azurerm provider.
|
||||
---
|
||||
|
||||
# azurerm\_client\_config
|
||||
|
||||
Use this data source to access the configuration
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
data "azurerm_client_config" "current" { }
|
||||
|
||||
output "account_id" {
|
||||
value = "${data.azurerm_client_config.current.account_id}"
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
There are no arguments available for this data source.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
`client_id` is set to the Azure Client ID.
|
||||
`tenant_id` is set to the Azure Tenant ID.
|
||||
`subscription_id` is set to the Azure Subscription ID.
|
|
@ -11,6 +11,15 @@
|
|||
<a href="/docs/providers/azurerm/index.html">Microsoft Azure Provider</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current(/^docs-azurerm-datasource/) %>>
|
||||
<a href="#">Data Sources</a>
|
||||
<ul class="nav nav-visible">
|
||||
<li<%= sidebar_current("docs-azurerm-datasource-client-config-") %>>
|
||||
<a href="/docs/providers/aws/d/client_config.html">azurerm_client_config</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current(/^docs-azurerm-resource-resource/) %>>
|
||||
<a href="#">Base Resources</a>
|
||||
<ul class="nav nav-visible">
|
||||
|
|
Loading…
Reference in New Issue