Skip to content

Commit

Permalink
Add the privateca certificate template resource. (#5109) (#9905)
Browse files Browse the repository at this point in the history
* 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 <ScottMSuarez@gmail.com>

* 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 <ScottMSuarez@gmail.com>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Scott Suarez <ScottMSuarez@gmail.com>
  • Loading branch information
modular-magician and ScottSuarez authored Aug 25, 2021
1 parent 6ac4ff3 commit c3eb6e9
Show file tree
Hide file tree
Showing 13 changed files with 2,038 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/5109.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_privateca_certificate_template`
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/hashicorp/terraform-provider-google
require (
cloud.google.com/go/bigtable v1.10.1
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210812005055-c5fc24943f87
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a
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
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOC
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM=
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a h1:k71tcjN3d1+YrSB1cN2d9T787JjbwbfNFM6HarBrn2o=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210623224421-7f5af5003bbb h1:9HBI5n77Z2ReBlOFk1h2JFLpY/HobH9Xaq90E7IjCpw=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210623224421-7f5af5003bbb/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210714164422-6d77a2179146 h1:vRS4+P5F6xj+04RtgRDAw62IOisi05fRT76MZGPjSM0=
Expand All @@ -77,6 +79,10 @@ github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-202108
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210803014808-0fdb1dc411b3/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210812005055-c5fc24943f87 h1:k1QG6P6FW079MKAzFsnNtzIXGHFaiSDZyWnPR5IBhqo=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210812005055-c5fc24943f87/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210818215311-28937690f4e1 h1:jRm6CS0h47NXOS6RLbMyxOXFDzTSXF9mcgevmXPolXk=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210818215311-28937690f4e1/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824014903-40e1b4c7517b h1:UXWsC3kaseg5NilrJUXVEstZ9E3xtMcGCAZt/VjBAkA=
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824014903-40e1b4c7517b/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU=
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
Expand Down
26 changes: 26 additions & 0 deletions google/expanders.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,29 @@ func expandStringArray(v interface{}) []string {
}
return arr
}

func expandIntegerArray(v interface{}) []int64 {
arr, ok := v.([]int64)

if ok {
return arr
}

if arr, ok := v.(*schema.Set); ok {
return convertIntegerSet(arr)
}

return convertIntegerArr(v.([]interface{}))
}

func convertIntegerSet(v *schema.Set) []int64 {
return convertIntegerArr(v.List())
}

func convertIntegerArr(v []interface{}) []int64 {
var vi []int64
for _, vs := range v {
vi = append(vi, int64(vs.(int)))
}
return vi
}
9 changes: 6 additions & 3 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,10 @@ func Provider() *schema.Provider {
BigtableAdminCustomEndpointEntryKey: BigtableAdminCustomEndpointEntry,

// dcl
AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
EventarcEndpointEntryKey: EventarcEndpointEntry,
GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry,
AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
EventarcEndpointEntryKey: EventarcEndpointEntry,
GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry,
PrivatecaCertificateTemplateEndpointEntryKey: PrivatecaCertificateTemplateCustomEndpointEntry,
},

ProviderMetaSchema: map[string]*schema.Schema{
Expand Down Expand Up @@ -1162,6 +1163,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_eventarc_trigger": resourceEventarcTrigger(),
"google_folder": resourceGoogleFolder(),
"google_folder_organization_policy": resourceGoogleFolderOrganizationPolicy(),
"google_privateca_certificate_template": resourcePrivatecaCertificateTemplate(),
"google_logging_billing_account_sink": resourceLoggingBillingAccountSink(),
"google_logging_billing_account_exclusion": ResourceLoggingExclusion(BillingAccountLoggingExclusionSchema, NewBillingAccountLoggingExclusionUpdater, billingAccountLoggingExclusionIdParseFunc),
"google_logging_billing_account_bucket_config": ResourceLoggingBillingAccountBucketConfig(),
Expand Down Expand Up @@ -1425,6 +1427,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
config.GkeHubBasePath = d.Get(GkeHubFeatureCustomEndpointEntryKey).(string)
config.PrivatecaBasePath = d.Get(PrivatecaCertificateTemplateEndpointEntryKey).(string)

stopCtx, ok := schema.StopContext(ctx)
if !ok {
Expand Down
20 changes: 20 additions & 0 deletions google/provider_dcl_client_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
compute "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/compute"
dataproc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataproc"
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc"
privateca "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/privateca"
)

func NewDCLAssuredWorkloadsClient(config *Config, userAgent, billingProject string) *assuredworkloads.Client {
Expand Down Expand Up @@ -99,3 +100,22 @@ func NewDCLEventarcClient(config *Config, userAgent, billingProject string) *eve
dclConfig := dcl.NewConfig(configOptions...)
return eventarc.NewClient(dclConfig)
}

func NewDCLPrivatecaClient(config *Config, userAgent, billingProject string) *privateca.Client {
configOptions := []dcl.ConfigOption{
dcl.WithHTTPClient(config.client),
dcl.WithUserAgent(userAgent),
dcl.WithLogger(dclLogger{}),
dcl.WithBasePath(config.PrivatecaBasePath),
}

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

dclConfig := dcl.NewConfig(configOptions...)
return privateca.NewClient(dclConfig)
}
12 changes: 12 additions & 0 deletions google/provider_dcl_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,29 @@ var EventarcEndpointEntry = &schema.Schema{
}, ""),
}

var PrivatecaEndpointEntryKey = "privateca_custom_endpoint"
var PrivatecaEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_PRIVATECA_CUSTOM_ENDPOINT",
}, ""),
}

//Add new values to config.go.erb config object declaration
//AssuredWorkloadsBasePath string
//ComputeBasePath string
//EventarcBasePath string
//PrivatecaBasePath string

//Add new values to provider.go.erb schema initialization
// AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
// ComputeEndpointEntryKey: ComputeEndpointEntry,
// EventarcEndpointEntryKey: EventarcEndpointEntry,
// PrivatecaEndpointEntryKey: PrivatecaEndpointEntry,

//Add new values to provider.go.erb - provider block read
// config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
// config.ComputeBasePath = d.Get(ComputeEndpointEntryKey).(string)
// config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
// config.PrivatecaBasePath = d.Get(PrivatecaEndpointEntryKey).(string)
10 changes: 10 additions & 0 deletions google/provider_handwritten_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ var GkeHubFeatureCustomEndpointEntry = &schema.Schema{
}, DefaultBasePaths[GkeHubFeatureBasePathKey]),
}

var PrivatecaCertificateTemplateEndpointEntryKey = "privateca_custom_endpoint"
var PrivatecaCertificateTemplateCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_PRIVATECA_CUSTOM_ENDPOINT",
}, DefaultBasePaths[PrivatecaBasePathKey]),
}

func validateCustomEndpoint(v interface{}, k string) (ws []string, errors []error) {
re := `.*/[^/]+/$`
return validateRegexp(re)(v, k)
Expand Down
Loading

0 comments on commit c3eb6e9

Please sign in to comment.