Skip to content

Commit

Permalink
Add default_labels to data source google_client_config (GoogleCloudPl…
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Aug 16, 2024
1 parent ea4c179 commit ef2d9c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type FrameworkProviderConfig struct {
UniverseDomain types.String
UserAgent string
UserProjectOverride types.Bool
DefaultLabels types.Map

// paths for client setup
<% products.each do |product| -%>
Expand Down Expand Up @@ -98,13 +99,13 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,

p.Context = ctx
p.BillingProject = data.BillingProject
p.DefaultLabels = data.DefaultLabels
p.Project = data.Project
p.Region = GetRegionFromRegionSelfLink(data.Region)
p.Scopes = data.Scopes
p.Zone = data.Zone
p.UserProjectOverride = data.UserProjectOverride
p.PollInterval = 10 * time.Second
p.Project = data.Project
p.UniverseDomain = data.UniverseDomain
p.RequestBatcherServiceUsage = transport_tpg.NewRequestBatcher("Service Usage", ctx, batchingConfig)
p.RequestBatcherIam = transport_tpg.NewRequestBatcher("IAM", ctx, batchingConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ type GoogleClientConfigDataSource struct {
type GoogleClientConfigModel struct {
// Id could/should be removed in future as it's not necessary in the plugin framework
// https://github.com/hashicorp/terraform-plugin-testing/issues/84
Id types.String `tfsdk:"id"`
Project types.String `tfsdk:"project"`
Region types.String `tfsdk:"region"`
Zone types.String `tfsdk:"zone"`
AccessToken types.String `tfsdk:"access_token"`
Id types.String `tfsdk:"id"`
Project types.String `tfsdk:"project"`
Region types.String `tfsdk:"region"`
Zone types.String `tfsdk:"zone"`
AccessToken types.String `tfsdk:"access_token"`
DefaultLabels types.Map `tfsdk:"default_labels"`
}

func (m *GoogleClientConfigModel) GetLocationDescription(providerConfig *fwtransport.FrameworkProviderConfig) fwresource.LocationDescription {
Expand Down Expand Up @@ -86,6 +87,12 @@ func (d *GoogleClientConfigDataSource) Schema(ctx context.Context, req datasourc
Computed: true,
Sensitive: true,
},
"default_labels": schema.MapAttribute{
Description: "The default labels configured on the provider.",
MarkdownDescription: "The default labels configured on the provider.",
Computed: true,
ElementType: types.StringType,
},
},
}
}
Expand Down Expand Up @@ -134,6 +141,7 @@ func (d *GoogleClientConfigDataSource) Read(ctx context.Context, req datasource.
data.Project = d.providerConfig.Project
data.Region = region
data.Zone = zone
data.DefaultLabels = d.providerConfig.DefaultLabels

token, err := d.providerConfig.TokenSource.Token()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestAccDataSourceGoogleClientConfig_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "region"),
resource.TestCheckResourceAttrSet(resourceName, "zone"),
resource.TestCheckResourceAttrSet(resourceName, "access_token"),
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.%", "1"),
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.default_key", "default_value"),
),
},
},
Expand All @@ -43,12 +45,20 @@ func TestAccDataSourceGoogleClientConfig_omitLocation(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project"),
resource.TestCheckResourceAttrSet(resourceName, "access_token"),
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.%", "1"),
resource.TestCheckResourceAttr("data.google_client_config.current", "default_labels.default_key", "default_value"),
),
},
},
})
}

const testAccCheckGoogleClientConfig_basic = `
provider "google" {
default_labels = {
default_key = "default_value"
}
}
data "google_client_config" "current" { }
`
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ In addition to the arguments listed above, the following attributes are exported
* `zone` - The zone to operate under.

* `access_token` - The OAuth2 access token used by the client to authenticate against the Google Cloud API.

* `default_labels` - The default labels configured on the provider.

0 comments on commit ef2d9c0

Please sign in to comment.