Skip to content

Commit 5a5a15f

Browse files
author
Nicholas M. Iodice
authored
Add data source for client configuration (#323)
1 parent bd66dd7 commit 5a5a15f

File tree

6 files changed

+103
-0
lines changed

6 files changed

+103
-0
lines changed

azuredevops/data_client_config.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package azuredevops
2+
3+
import (
4+
"time"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/utils/config"
8+
)
9+
10+
const (
11+
organizationURL = "organization_url"
12+
)
13+
14+
func dataClientConfig() *schema.Resource {
15+
return &schema.Resource{
16+
Read: clientConfigRead,
17+
Schema: map[string]*schema.Schema{
18+
organizationURL: {
19+
Type: schema.TypeString,
20+
Computed: true,
21+
},
22+
},
23+
}
24+
}
25+
26+
func clientConfigRead(d *schema.ResourceData, m interface{}) error {
27+
// The ID is meaningless for this data source, so ID can act as a
28+
// point in time snapshot
29+
d.SetId(time.Now().UTC().String())
30+
d.Set(organizationURL, m.(*config.AggregatedClient).OrganizationURL)
31+
return nil
32+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// +build all core
2+
3+
package azuredevops
4+
5+
import (
6+
"os"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10+
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/utils/testhelper"
11+
)
12+
13+
/**
14+
* Begin acceptance tests
15+
*/
16+
17+
// Verifies that the client config data source loads the configured AzDO org
18+
func TestAccClientConfig_LoadsCorrectProperties(t *testing.T) {
19+
tfNode := "data.azuredevops_client_config.c"
20+
resource.Test(t, resource.TestCase{
21+
PreCheck: func() { testhelper.TestAccPreCheck(t, nil) },
22+
Providers: testAccProviders,
23+
Steps: []resource.TestStep{
24+
{
25+
Config: `data "azuredevops_client_config" "c" {}`,
26+
Check: resource.ComposeTestCheckFunc(
27+
resource.TestCheckResourceAttrSet(tfNode, "id"),
28+
resource.TestCheckResourceAttr(tfNode, "organization_url", os.Getenv("AZDO_ORG_SERVICE_URL")),
29+
),
30+
},
31+
},
32+
})
33+
}
34+
35+
func init() {
36+
InitProvider()
37+
}

azuredevops/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func Provider() *schema.Provider {
2525
"azuredevops_group": resourceGroup(),
2626
},
2727
DataSourcesMap: map[string]*schema.Resource{
28+
"azuredevops_client_config": dataClientConfig(),
2829
"azuredevops_group": dataGroup(),
2930
"azuredevops_project": dataProject(),
3031
"azuredevops_projects": dataProjects(),

azuredevops/provider_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestAzureDevOpsProvider_HasChildResources(t *testing.T) {
4242

4343
func TestAzureDevOpsProvider_HasChildDataSources(t *testing.T) {
4444
expectedDataSources := []string{
45+
"azuredevops_client_config",
4546
"azuredevops_group",
4647
"azuredevops_project",
4748
"azuredevops_projects",

azuredevops/utils/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
// allow for mocking to support unit testing of the funcs that invoke the
2929
// Azure DevOps client.
3030
type AggregatedClient struct {
31+
OrganizationURL string
3132
CoreClient core.Client
3233
BuildClient build.Client
3334
GitReposClient git.Client
@@ -111,6 +112,7 @@ func GetAzdoClient(azdoPAT string, organizationURL string, tfVersion string) (*A
111112
}
112113

113114
aggregatedClient := &AggregatedClient{
115+
OrganizationURL: organizationURL,
114116
CoreClient: coreClient,
115117
BuildClient: buildClient,
116118
GitReposClient: gitReposClient,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
layout: "azuredevops"
3+
page_title: "AzureDevops: azuredevops_client_config"
4+
description: |-
5+
Use this data source to access information about the Azure DevOps organization configured for the provider.
6+
---
7+
8+
# Data Source: azuredevops_client_config
9+
10+
Use this data source to access information about the Azure DevOps organization configured for the provider.
11+
12+
## Example Usage
13+
14+
```hcl
15+
data "azuredevops_client_config" "c" {}
16+
17+
output "org_url" {
18+
value = data.azuredevops_client_config.c.organization_url
19+
}
20+
```
21+
22+
## Argument Reference
23+
24+
This data source has no arguments
25+
26+
## Attributes Reference
27+
28+
The following attributes are exported:
29+
30+
`organization_url` - The organization configured for the provider

0 commit comments

Comments
 (0)