Skip to content

Commit

Permalink
Add apikeys key resource (#5637) (#11249)
Browse files Browse the repository at this point in the history
* Add apikeys key resource

* Update branch

* Update go.mod & sum for required fields

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 9, 2022
1 parent a064dbe commit 237509a
Show file tree
Hide file tree
Showing 15 changed files with 1,571 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .changelog/5637.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
google_apikeys_key
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/hashicorp/terraform-provider-google
require (
cloud.google.com/go/bigtable v1.10.1
cloud.google.com/go/iam v0.1.1 // indirect
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220304175357-35332d17a512
github.com/apparentlymart/go-cidr v1.1.0
github.com/client9/misspell v0.3.4
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1530,4 +1530,6 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637 h1:+s2wWcAciNo96AT+Ci9pwXuWm9qlY/ubLFWRaqE0tZg=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220225200700-e76d50f1e637/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220304175357-35332d17a512 h1:8/Sn9pDdk/RxECtLUh4xum2eyUvf0h7bpx8h+lYvE+Q=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220304175357-35332d17a512/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
1 change: 1 addition & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type Config struct {
NetworkConnectivityBasePath string
OrgPolicyBasePath string
RecaptchaEnterpriseBasePath string
ApikeysBasePath string
// CloudBuild WorkerPool uses a different endpoint (v1beta1) than any other CloudBuild resources
CloudBuildWorkerPoolBasePath string
}
Expand Down
3 changes: 3 additions & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ func Provider() *schema.Provider {
RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry,
ContainerAwsCustomEndpointEntryKey: ContainerAwsCustomEndpointEntry,
ContainerAzureCustomEndpointEntryKey: ContainerAzureCustomEndpointEntry,
ApikeysEndpointEntryKey: ApikeysEndpointEntry,

CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
},
Expand Down Expand Up @@ -1219,6 +1220,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
},
// resources implemented within tpgtools
map[string]*schema.Resource{
"google_apikeys_key": resourceApikeysKey(),
"google_assured_workloads_workload": resourceAssuredWorkloadsWorkload(),
"google_cloudbuild_worker_pool": resourceCloudbuildWorkerPool(),
"google_compute_firewall_policy_association": resourceComputeFirewallPolicyAssociation(),
Expand Down Expand Up @@ -1466,6 +1468,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.BigtableAdminBasePath = d.Get(BigtableAdminCustomEndpointEntryKey).(string)

// dcl
config.ApikeysBasePath = d.Get(ApikeysEndpointEntryKey).(string)
config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
config.CloudResourceManagerBasePath = d.Get(CloudResourceManagerEndpointEntryKey).(string)
config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
Expand Down
24 changes: 24 additions & 0 deletions google/provider_dcl_client_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
"time"

apikeys "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/apikeys"
assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads"
bigqueryreservation "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/bigqueryreservation"
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild"
Expand All @@ -35,6 +36,29 @@ import (
recaptchaenterprise "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/recaptchaenterprise"
)

func NewDCLApikeysClient(config *Config, userAgent, billingProject string, timeout time.Duration) *apikeys.Client {
configOptions := []dcl.ConfigOption{
dcl.WithHTTPClient(config.client),
dcl.WithUserAgent(userAgent),
dcl.WithLogger(dclLogger{}),
dcl.WithBasePath(config.ApikeysBasePath),
}

if timeout != 0 {
configOptions = append(configOptions, dcl.WithTimeout(timeout))
}

if config.UserProjectOverride {
configOptions = append(configOptions, dcl.WithUserProjectOverride())
if billingProject != "" {
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
}
}

dclConfig := dcl.NewConfig(configOptions...)
return apikeys.NewClient(dclConfig)
}

func NewDCLAssuredWorkloadsClient(config *Config, userAgent, billingProject string, timeout time.Duration) *assuredworkloads.Client {
configOptions := []dcl.ConfigOption{
dcl.WithHTTPClient(config.client),
Expand Down
12 changes: 12 additions & 0 deletions google/provider_dcl_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import (
// empty string is passed for dcl default since dcl
// [hardcodes the values](https://github.com/GoogleCloudPlatform/declarative-resource-client-library/blob/main/services/google/eventarc/beta/trigger_internal.go#L96-L103)

var ApikeysEndpointEntryKey = "apikeys_custom_endpoint"
var ApikeysEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_APIKEYS_CUSTOM_ENDPOINT",
}, ""),
}

var AssuredWorkloadsEndpointEntryKey = "assured_workloads_custom_endpoint"
var AssuredWorkloadsEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -131,6 +140,7 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
}

//Add new values to config.go.erb config object declaration
//ApikeysBasePath string
//AssuredWorkloadsBasePath string
//CloudBuildWorkerPoolBasePath string
//CloudResourceManagerBasePath string
Expand All @@ -145,6 +155,7 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
//RecaptchaEnterpriseBasePath string

//Add new values to provider.go.erb schema initialization
// ApikeysEndpointEntryKey: ApikeysEndpointEntry,
// AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
// CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
// CloudResourceManagerEndpointEntryKey: CloudResourceManagerEndpointEntry,
Expand All @@ -159,6 +170,7 @@ var RecaptchaEnterpriseEndpointEntry = &schema.Schema{
// RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry,

//Add new values to provider.go.erb - provider block read
// config.ApikeysBasePath = d.Get(ApikeysEndpointEntryKey).(string)
// config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
// config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
// config.CloudResourceManagerBasePath = d.Get(CloudResourceManagerEndpointEntryKey).(string)
Expand Down
Loading

0 comments on commit 237509a

Please sign in to comment.