Skip to content

Commit 27b9abb

Browse files
Add the privateca certificate template resource. (#5109) (#3561)
* Add the privateca certificate template resource. * update serialization code so that the sample test can be autogenerated. * fix minor issues in samples generation code (underscores vs title vase) * add privateca to provider * add ability to expand and flatten int arrays. * remove cloud run serialization (and relevant tests) since it no longer exists in the DCL. * add go.sum entry for new dcl. * Apply suggestions from code review Co-authored-by: Scott Suarez <[email protected]> * Add beta version of privateca certificate template. * Update serialization. * Upgrade to version of DCL that can handle pointers to objects which are set but contain only fields which are set but empty. Co-authored-by: Scott Suarez <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Scott Suarez <[email protected]>
1 parent 8879d77 commit 27b9abb

13 files changed

+2039
-4
lines changed

.changelog/5109.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_privateca_certificate_template`
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/hashicorp/terraform-provider-google-beta
22
require (
33
cloud.google.com/go/bigtable v1.10.1
4-
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210812005055-c5fc24943f87
4+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a
55
github.com/apparentlymart/go-cidr v1.1.0
66
github.com/client9/misspell v0.3.4
77
github.com/davecgh/go-spew v1.1.1

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOC
6767
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
6868
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM=
6969
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
70+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a h1:k71tcjN3d1+YrSB1cN2d9T787JjbwbfNFM6HarBrn2o=
71+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
7072
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210623224421-7f5af5003bbb h1:9HBI5n77Z2ReBlOFk1h2JFLpY/HobH9Xaq90E7IjCpw=
7173
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210623224421-7f5af5003bbb/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
7274
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210714164422-6d77a2179146 h1:vRS4+P5F6xj+04RtgRDAw62IOisi05fRT76MZGPjSM0=
@@ -77,6 +79,10 @@ github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-202108
7779
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210803014808-0fdb1dc411b3/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
7880
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210812005055-c5fc24943f87 h1:k1QG6P6FW079MKAzFsnNtzIXGHFaiSDZyWnPR5IBhqo=
7981
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210812005055-c5fc24943f87/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
82+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210818215311-28937690f4e1 h1:jRm6CS0h47NXOS6RLbMyxOXFDzTSXF9mcgevmXPolXk=
83+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210818215311-28937690f4e1/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
84+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824014903-40e1b4c7517b h1:UXWsC3kaseg5NilrJUXVEstZ9E3xtMcGCAZt/VjBAkA=
85+
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824014903-40e1b4c7517b/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
8086
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
8187
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
8288
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=

google-beta/expanders.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,29 @@ func expandStringArray(v interface{}) []string {
2020
}
2121
return arr
2222
}
23+
24+
func expandIntegerArray(v interface{}) []int64 {
25+
arr, ok := v.([]int64)
26+
27+
if ok {
28+
return arr
29+
}
30+
31+
if arr, ok := v.(*schema.Set); ok {
32+
return convertIntegerSet(arr)
33+
}
34+
35+
return convertIntegerArr(v.([]interface{}))
36+
}
37+
38+
func convertIntegerSet(v *schema.Set) []int64 {
39+
return convertIntegerArr(v.List())
40+
}
41+
42+
func convertIntegerArr(v []interface{}) []int64 {
43+
var vi []int64
44+
for _, vs := range v {
45+
vi = append(vi, int64(vs.(int)))
46+
}
47+
return vi
48+
}

google-beta/provider.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,11 @@ func Provider() *schema.Provider {
766766
BigtableAdminCustomEndpointEntryKey: BigtableAdminCustomEndpointEntry,
767767

768768
// dcl
769-
AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
770-
EventarcEndpointEntryKey: EventarcEndpointEntry,
771-
GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry,
769+
AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
770+
EventarcEndpointEntryKey: EventarcEndpointEntry,
771+
GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry,
772+
PrivatecaCertificateTemplateEndpointEntryKey: PrivatecaCertificateTemplateCustomEndpointEntry,
773+
772774
CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
773775
},
774776

@@ -1298,6 +1300,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
12981300
"google_eventarc_trigger": resourceEventarcTrigger(),
12991301
"google_folder": resourceGoogleFolder(),
13001302
"google_folder_organization_policy": resourceGoogleFolderOrganizationPolicy(),
1303+
"google_privateca_certificate_template": resourcePrivatecaCertificateTemplate(),
13011304
"google_gke_hub_feature": resourceGkeHubFeature(),
13021305
"google_gke_hub_feature_membership": resourceGkeHubFeatureMembership(),
13031306
"google_logging_billing_account_sink": resourceLoggingBillingAccountSink(),
@@ -1573,6 +1576,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
15731576
config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
15741577
config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
15751578
config.GkeHubBasePath = d.Get(GkeHubFeatureCustomEndpointEntryKey).(string)
1579+
config.PrivatecaBasePath = d.Get(PrivatecaCertificateTemplateEndpointEntryKey).(string)
15761580
config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
15771581

15781582
stopCtx, ok := schema.StopContext(ctx)

google-beta/provider_dcl_client_creation.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
dataproc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataproc/beta"
2525
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc/beta"
2626
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
27+
privateca "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/privateca/beta"
2728
)
2829

2930
func NewDCLAssuredWorkloadsClient(config *Config, userAgent, billingProject string) *assuredworkloads.Client {
@@ -139,3 +140,22 @@ func NewDCLGkeHubClient(config *Config, userAgent, billingProject string) *gkehu
139140
dclConfig := dcl.NewConfig(configOptions...)
140141
return gkehub.NewClient(dclConfig)
141142
}
143+
144+
func NewDCLPrivatecaClient(config *Config, userAgent, billingProject string) *privateca.Client {
145+
configOptions := []dcl.ConfigOption{
146+
dcl.WithHTTPClient(config.client),
147+
dcl.WithUserAgent(userAgent),
148+
dcl.WithLogger(dclLogger{}),
149+
dcl.WithBasePath(config.PrivatecaBasePath),
150+
}
151+
152+
if config.UserProjectOverride {
153+
configOptions = append(configOptions, dcl.WithUserProjectOverride())
154+
if billingProject != "" {
155+
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
156+
}
157+
}
158+
159+
dclConfig := dcl.NewConfig(configOptions...)
160+
return privateca.NewClient(dclConfig)
161+
}

google-beta/provider_dcl_endpoints.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,32 @@ var EventarcEndpointEntry = &schema.Schema{
5858
}, ""),
5959
}
6060

61+
var PrivatecaEndpointEntryKey = "privateca_custom_endpoint"
62+
var PrivatecaEndpointEntry = &schema.Schema{
63+
Type: schema.TypeString,
64+
Optional: true,
65+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
66+
"GOOGLE_PRIVATECA_CUSTOM_ENDPOINT",
67+
}, ""),
68+
}
69+
6170
//Add new values to config.go.erb config object declaration
6271
//AssuredWorkloadsBasePath string
6372
//CloudBuildWorkerPoolBasePath string
6473
//ComputeBasePath string
6574
//EventarcBasePath string
75+
//PrivatecaBasePath string
6676

6777
//Add new values to provider.go.erb schema initialization
6878
// AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
6979
// CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
7080
// ComputeEndpointEntryKey: ComputeEndpointEntry,
7181
// EventarcEndpointEntryKey: EventarcEndpointEntry,
82+
// PrivatecaEndpointEntryKey: PrivatecaEndpointEntry,
7283

7384
//Add new values to provider.go.erb - provider block read
7485
// config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
7586
// config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
7687
// config.ComputeBasePath = d.Get(ComputeEndpointEntryKey).(string)
7788
// config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
89+
// config.PrivatecaBasePath = d.Get(PrivatecaEndpointEntryKey).(string)

google-beta/provider_handwritten_endpoint.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ var GkeHubFeatureCustomEndpointEntry = &schema.Schema{
169169
}, DefaultBasePaths[GkeHubFeatureBasePathKey]),
170170
}
171171

172+
var PrivatecaCertificateTemplateEndpointEntryKey = "privateca_custom_endpoint"
173+
var PrivatecaCertificateTemplateCustomEndpointEntry = &schema.Schema{
174+
Type: schema.TypeString,
175+
Optional: true,
176+
ValidateFunc: validateCustomEndpoint,
177+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
178+
"GOOGLE_PRIVATECA_CUSTOM_ENDPOINT",
179+
}, DefaultBasePaths[PrivatecaBasePathKey]),
180+
}
181+
172182
func validateCustomEndpoint(v interface{}, k string) (ws []string, errors []error) {
173183
re := `.*/[^/]+/$`
174184
return validateRegexp(re)(v, k)

0 commit comments

Comments
 (0)