Skip to content

Commit 33640cc

Browse files
Add default_labels to data source google_client_config (#11447) (#19170)
[upstream:ef2d9c06c5693f87a7e979215e6d0ee9b396105a] Signed-off-by: Modular Magician <[email protected]>
1 parent f9df354 commit 33640cc

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.changelog/11447.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resourcemanager: added `default_labels` field to `google_client_config` data source
3+
```

google/fwtransport/framework_config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type FrameworkProviderConfig struct {
4949
UniverseDomain types.String
5050
UserAgent string
5151
UserProjectOverride types.Bool
52+
DefaultLabels types.Map
5253

5354
// paths for client setup
5455
AccessApprovalBasePath string
@@ -335,13 +336,13 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
335336

336337
p.Context = ctx
337338
p.BillingProject = data.BillingProject
339+
p.DefaultLabels = data.DefaultLabels
338340
p.Project = data.Project
339341
p.Region = GetRegionFromRegionSelfLink(data.Region)
340342
p.Scopes = data.Scopes
341343
p.Zone = data.Zone
342344
p.UserProjectOverride = data.UserProjectOverride
343345
p.PollInterval = 10 * time.Second
344-
p.Project = data.Project
345346
p.UniverseDomain = data.UniverseDomain
346347
p.RequestBatcherServiceUsage = transport_tpg.NewRequestBatcher("Service Usage", ctx, batchingConfig)
347348
p.RequestBatcherIam = transport_tpg.NewRequestBatcher("IAM", ctx, batchingConfig)

google/services/resourcemanager/data_source_google_client_config.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ type GoogleClientConfigDataSource struct {
3333
type GoogleClientConfigModel struct {
3434
// Id could/should be removed in future as it's not necessary in the plugin framework
3535
// https://github.com/hashicorp/terraform-plugin-testing/issues/84
36-
Id types.String `tfsdk:"id"`
37-
Project types.String `tfsdk:"project"`
38-
Region types.String `tfsdk:"region"`
39-
Zone types.String `tfsdk:"zone"`
40-
AccessToken types.String `tfsdk:"access_token"`
36+
Id types.String `tfsdk:"id"`
37+
Project types.String `tfsdk:"project"`
38+
Region types.String `tfsdk:"region"`
39+
Zone types.String `tfsdk:"zone"`
40+
AccessToken types.String `tfsdk:"access_token"`
41+
DefaultLabels types.Map `tfsdk:"default_labels"`
4142
}
4243

4344
func (m *GoogleClientConfigModel) GetLocationDescription(providerConfig *fwtransport.FrameworkProviderConfig) fwresource.LocationDescription {
@@ -88,6 +89,12 @@ func (d *GoogleClientConfigDataSource) Schema(ctx context.Context, req datasourc
8889
Computed: true,
8990
Sensitive: true,
9091
},
92+
"default_labels": schema.MapAttribute{
93+
Description: "The default labels configured on the provider.",
94+
MarkdownDescription: "The default labels configured on the provider.",
95+
Computed: true,
96+
ElementType: types.StringType,
97+
},
9198
},
9299
}
93100
}
@@ -136,6 +143,7 @@ func (d *GoogleClientConfigDataSource) Read(ctx context.Context, req datasource.
136143
data.Project = d.providerConfig.Project
137144
data.Region = region
138145
data.Zone = zone
146+
data.DefaultLabels = d.providerConfig.DefaultLabels
139147

140148
token, err := d.providerConfig.TokenSource.Token()
141149
if err != nil {

google/services/resourcemanager/data_source_google_client_config_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func TestAccDataSourceGoogleClientConfig_basic(t *testing.T) {
2525
resource.TestCheckResourceAttrSet(resourceName, "region"),
2626
resource.TestCheckResourceAttrSet(resourceName, "zone"),
2727
resource.TestCheckResourceAttrSet(resourceName, "access_token"),
28+
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.%", "1"),
29+
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.default_key", "default_value"),
2830
),
2931
},
3032
},
@@ -45,12 +47,20 @@ func TestAccDataSourceGoogleClientConfig_omitLocation(t *testing.T) {
4547
Check: resource.ComposeTestCheckFunc(
4648
resource.TestCheckResourceAttrSet(resourceName, "project"),
4749
resource.TestCheckResourceAttrSet(resourceName, "access_token"),
50+
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.%", "1"),
51+
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.default_key", "default_value"),
4852
),
4953
},
5054
},
5155
})
5256
}
5357

5458
const testAccCheckGoogleClientConfig_basic = `
59+
provider "google" {
60+
default_labels = {
61+
default_key = "default_value"
62+
}
63+
}
64+
5565
data "google_client_config" "current" { }
5666
`

website/docs/d/client_config.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ In addition to the arguments listed above, the following attributes are exported
5757
* `zone` - The zone to operate under.
5858

5959
* `access_token` - The OAuth2 access token used by the client to authenticate against the Google Cloud API.
60+
61+
* `default_labels` - The default labels configured on the provider.

0 commit comments

Comments
 (0)