Skip to content

Commit e476502

Browse files
Add apikeys key resource (#5637) (#4114)
* Add apikeys key resource * Update branch * Update go.mod & sum for required fields Signed-off-by: Modular Magician <[email protected]>
1 parent a2132a0 commit e476502

15 files changed

+1571
-25
lines changed

.changelog/5637.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
google_apikeys_key
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/hashicorp/terraform-provider-google-beta
22
require (
33
cloud.google.com/go/bigtable v1.10.1
44
cloud.google.com/go/iam v0.1.1 // indirect
5-
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637
5+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220304175357-35332d17a512
66
github.com/apparentlymart/go-cidr v1.1.0
77
github.com/client9/misspell v0.3.4
88
github.com/davecgh/go-spew v1.1.1

go.sum

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,4 +1530,6 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
15301530
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
15311531
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
15321532
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637 h1:+s2wWcAciNo96AT+Ci9pwXuWm9qlY/ubLFWRaqE0tZg=
1533-
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
1533+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
1534+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220304175357-35332d17a512 h1:8/Sn9pDdk/RxECtLUh4xum2eyUvf0h7bpx8h+lYvE+Q=
1535+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220304175357-35332d17a512/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=

google-beta/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ type Config struct {
264264
NetworkConnectivityBasePath string
265265
OrgPolicyBasePath string
266266
RecaptchaEnterpriseBasePath string
267+
ApikeysBasePath string
267268
// CloudBuild WorkerPool uses a different endpoint (v1beta1) than any other CloudBuild resources
268269
CloudBuildWorkerPoolBasePath string
269270
}

google-beta/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ func Provider() *schema.Provider {
783783
RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry,
784784
ContainerAwsCustomEndpointEntryKey: ContainerAwsCustomEndpointEntry,
785785
ContainerAzureCustomEndpointEntryKey: ContainerAzureCustomEndpointEntry,
786+
ApikeysEndpointEntryKey: ApikeysEndpointEntry,
786787

787788
CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
788789
},
@@ -1377,6 +1378,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
13771378
},
13781379
// resources implemented within tpgtools
13791380
map[string]*schema.Resource{
1381+
"google_apikeys_key": resourceApikeysKey(),
13801382
"google_assured_workloads_workload": resourceAssuredWorkloadsWorkload(),
13811383
"google_cloudbuild_worker_pool": resourceCloudbuildWorkerPool(),
13821384
"google_compute_firewall_policy_association": resourceComputeFirewallPolicyAssociation(),
@@ -1638,6 +1640,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
16381640
config.BigtableAdminBasePath = d.Get(BigtableAdminCustomEndpointEntryKey).(string)
16391641

16401642
// dcl
1643+
config.ApikeysBasePath = d.Get(ApikeysEndpointEntryKey).(string)
16411644
config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
16421645
config.CloudResourceManagerBasePath = d.Get(CloudResourceManagerEndpointEntryKey).(string)
16431646
config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)

google-beta/provider_dcl_client_creation.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
2020
"time"
2121

22+
apikeys "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/apikeys/beta"
2223
assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads/beta"
2324
bigqueryreservation "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/bigqueryreservation/beta"
2425
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild/beta"
@@ -37,6 +38,29 @@ import (
3738
recaptchaenterprise "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/recaptchaenterprise/beta"
3839
)
3940

41+
func NewDCLApikeysClient(config *Config, userAgent, billingProject string, timeout time.Duration) *apikeys.Client {
42+
configOptions := []dcl.ConfigOption{
43+
dcl.WithHTTPClient(config.client),
44+
dcl.WithUserAgent(userAgent),
45+
dcl.WithLogger(dclLogger{}),
46+
dcl.WithBasePath(config.ApikeysBasePath),
47+
}
48+
49+
if timeout != 0 {
50+
configOptions = append(configOptions, dcl.WithTimeout(timeout))
51+
}
52+
53+
if config.UserProjectOverride {
54+
configOptions = append(configOptions, dcl.WithUserProjectOverride())
55+
if billingProject != "" {
56+
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
57+
}
58+
}
59+
60+
dclConfig := dcl.NewConfig(configOptions...)
61+
return apikeys.NewClient(dclConfig)
62+
}
63+
4064
func NewDCLAssuredWorkloadsClient(config *Config, userAgent, billingProject string, timeout time.Duration) *assuredworkloads.Client {
4165
configOptions := []dcl.ConfigOption{
4266
dcl.WithHTTPClient(config.client),

google-beta/provider_dcl_endpoints.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ import (
2222
// empty string is passed for dcl default since dcl
2323
// [hardcodes the values](https://github.com/GoogleCloudPlatform/declarative-resource-client-library/blob/main/services/google/eventarc/beta/trigger_internal.go#L96-L103)
2424

25+
var ApikeysEndpointEntryKey = "apikeys_custom_endpoint"
26+
var ApikeysEndpointEntry = &schema.Schema{
27+
Type: schema.TypeString,
28+
Optional: true,
29+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
30+
"GOOGLE_APIKEYS_CUSTOM_ENDPOINT",
31+
}, ""),
32+
}
33+
2534
var AssuredWorkloadsEndpointEntryKey = "assured_workloads_custom_endpoint"
2635
var AssuredWorkloadsEndpointEntry = &schema.Schema{
2736
Type: schema.TypeString,
@@ -140,6 +149,7 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
140149
}
141150

142151
//Add new values to config.go.erb config object declaration
152+
//ApikeysBasePath string
143153
//AssuredWorkloadsBasePath string
144154
//CloudBuildWorkerPoolBasePath string
145155
//CloudResourceManagerBasePath string
@@ -155,6 +165,7 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
155165
//RecaptchaEnterpriseBasePath string
156166

157167
//Add new values to provider.go.erb schema initialization
168+
// ApikeysEndpointEntryKey: ApikeysEndpointEntry,
158169
// AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
159170
// CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
160171
// CloudResourceManagerEndpointEntryKey: CloudResourceManagerEndpointEntry,
@@ -170,6 +181,7 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
170181
// RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry,
171182

172183
//Add new values to provider.go.erb - provider block read
184+
// config.ApikeysBasePath = d.Get(ApikeysEndpointEntryKey).(string)
173185
// config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
174186
// config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
175187
// config.CloudResourceManagerBasePath = d.Get(CloudResourceManagerEndpointEntryKey).(string)

0 commit comments

Comments
 (0)