From c3eb6e9c9d5365c5c54411ae3ecb52d1f7eba391 Mon Sep 17 00:00:00 2001 From: The Magician <magic-modules@google.com> Date: Tue, 24 Aug 2021 20:01:18 -0500 Subject: [PATCH] Add the privateca certificate template resource. (#5109) (#9905) * 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> --- .changelog/5109.txt | 3 + go.mod | 2 +- go.sum | 6 + google/expanders.go | 26 + google/provider.go | 9 +- google/provider_dcl_client_creation.go | 20 + google/provider_dcl_endpoints.go | 12 + google/provider_handwritten_endpoint.go | 10 + ...resource_privateca_certificate_template.go | 1227 +++++++++++++++++ ...eca_certificate_template_generated_test.go | 265 ++++ ...ateca_certificate_template_sweeper_test.go | 72 + ...ivateca_certificate_template.html.markdown | 374 +++++ website/google.erb | 16 + 13 files changed, 2038 insertions(+), 4 deletions(-) create mode 100644 .changelog/5109.txt create mode 100644 google/resource_privateca_certificate_template.go create mode 100644 google/resource_privateca_certificate_template_generated_test.go create mode 100644 google/resource_privateca_certificate_template_sweeper_test.go create mode 100644 website/docs/r/privateca_certificate_template.html.markdown diff --git a/.changelog/5109.txt b/.changelog/5109.txt new file mode 100644 index 00000000000..b68fc61bd5d --- /dev/null +++ b/.changelog/5109.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_privateca_certificate_template` +``` diff --git a/go.mod b/go.mod index 53378416d8d..bfde44eff8d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b88429ece63..7fc3f73e5e8 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/google/expanders.go b/google/expanders.go index 98fd012b8e3..677773cf378 100644 --- a/google/expanders.go +++ b/google/expanders.go @@ -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 +} diff --git a/google/provider.go b/google/provider.go index c37a7968c46..f4a300a3eb2 100644 --- a/google/provider.go +++ b/google/provider.go @@ -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{ @@ -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(), @@ -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 { diff --git a/google/provider_dcl_client_creation.go b/google/provider_dcl_client_creation.go index 15974d6d1a4..7dfd098ee41 100644 --- a/google/provider_dcl_client_creation.go +++ b/google/provider_dcl_client_creation.go @@ -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 { @@ -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) +} diff --git a/google/provider_dcl_endpoints.go b/google/provider_dcl_endpoints.go index e0ba1642f2a..c55cb3551ca 100644 --- a/google/provider_dcl_endpoints.go +++ b/google/provider_dcl_endpoints.go @@ -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) diff --git a/google/provider_handwritten_endpoint.go b/google/provider_handwritten_endpoint.go index d27531e7035..691651a6ff6 100644 --- a/google/provider_handwritten_endpoint.go +++ b/google/provider_handwritten_endpoint.go @@ -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) diff --git a/google/resource_privateca_certificate_template.go b/google/resource_privateca_certificate_template.go new file mode 100644 index 00000000000..5701b19bf06 --- /dev/null +++ b/google/resource_privateca_certificate_template.go @@ -0,0 +1,1227 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: DCL *** +// +// ---------------------------------------------------------------------------- +// +// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules) +// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library). +// Changes will need to be made to the DCL or Magic Modules instead of here. +// +// We are not currently able to accept contributions to this file. If changes +// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" + privateca "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/privateca" +) + +func resourcePrivatecaCertificateTemplate() *schema.Resource { + return &schema.Resource{ + Create: resourcePrivatecaCertificateTemplateCreate, + Read: resourcePrivatecaCertificateTemplateRead, + Update: resourcePrivatecaCertificateTemplateUpdate, + Delete: resourcePrivatecaCertificateTemplateDelete, + + Importer: &schema.ResourceImporter{ + State: resourcePrivatecaCertificateTemplateImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "location": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: ``, + }, + + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: ``, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + Description: ``, + }, + + "identity_constraints": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplateIdentityConstraintsSchema(), + }, + + "labels": { + Type: schema.TypeMap, + Optional: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "passthrough_extensions": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePassthroughExtensionsSchema(), + }, + + "predefined_values": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePredefinedValuesSchema(), + }, + + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + Description: ``, + }, + + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: ``, + }, + + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: ``, + }, + }, + } +} + +func PrivatecaCertificateTemplateIdentityConstraintsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "allow_subject_alt_names_passthrough": { + Type: schema.TypeBool, + Required: true, + Description: ``, + }, + + "allow_subject_passthrough": { + Type: schema.TypeBool, + Required: true, + Description: ``, + }, + + "cel_expression": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplateIdentityConstraintsCelExpressionSchema(), + }, + }, + } +} + +func PrivatecaCertificateTemplateIdentityConstraintsCelExpressionSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "description": { + Type: schema.TypeString, + Optional: true, + Description: ``, + }, + + "expression": { + Type: schema.TypeString, + Optional: true, + Description: ``, + }, + + "location": { + Type: schema.TypeString, + Optional: true, + Description: ``, + }, + + "title": { + Type: schema.TypeString, + Optional: true, + Description: ``, + }, + }, + } +} + +func PrivatecaCertificateTemplatePassthroughExtensionsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "additional_extensions": { + Type: schema.TypeList, + Optional: true, + Description: ``, + Elem: PrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensionsSchema(), + }, + + "known_extensions": { + Type: schema.TypeList, + Optional: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func PrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensionsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "object_id_path": { + Type: schema.TypeList, + Required: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "additional_extensions": { + Type: schema.TypeList, + Optional: true, + Description: ``, + Elem: PrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsSchema(), + }, + + "aia_ocsp_servers": { + Type: schema.TypeList, + Optional: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "ca_options": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePredefinedValuesCaOptionsSchema(), + }, + + "key_usage": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePredefinedValuesKeyUsageSchema(), + }, + + "policy_ids": { + Type: schema.TypeList, + Optional: true, + Description: ``, + Elem: PrivatecaCertificateTemplatePredefinedValuesPolicyIdsSchema(), + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "object_id": { + Type: schema.TypeList, + Required: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsObjectIdSchema(), + }, + + "value": { + Type: schema.TypeString, + Required: true, + Description: ``, + }, + + "critical": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsObjectIdSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "object_id_path": { + Type: schema.TypeList, + Required: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesCaOptionsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "is_ca": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "max_issuer_path_length": { + Type: schema.TypeInt, + Optional: true, + Description: ``, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesKeyUsageSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "base_key_usage": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsageSchema(), + }, + + "extended_key_usage": { + Type: schema.TypeList, + Optional: true, + Description: ``, + MaxItems: 1, + Elem: PrivatecaCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsageSchema(), + }, + + "unknown_extended_key_usages": { + Type: schema.TypeList, + Optional: true, + Description: ``, + Elem: PrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsagesSchema(), + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsageSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cert_sign": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "content_commitment": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "crl_sign": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "data_encipherment": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "decipher_only": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "digital_signature": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "encipher_only": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "key_agreement": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "key_encipherment": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsageSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_auth": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "code_signing": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "email_protection": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "ocsp_signing": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "server_auth": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + + "time_stamping": { + Type: schema.TypeBool, + Optional: true, + Description: ``, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsagesSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "object_id_path": { + Type: schema.TypeList, + Required: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + }, + } +} + +func PrivatecaCertificateTemplatePredefinedValuesPolicyIdsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "object_id_path": { + Type: schema.TypeList, + Required: true, + Description: ``, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + }, + } +} + +func resourcePrivatecaCertificateTemplateCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + project, err := getProject(d, config) + if err != nil { + return err + } + + obj := &privateca.CertificateTemplate{ + Location: dcl.String(d.Get("location").(string)), + Name: dcl.String(d.Get("name").(string)), + Description: dcl.String(d.Get("description").(string)), + IdentityConstraints: expandPrivatecaCertificateTemplateIdentityConstraints(d.Get("identity_constraints")), + Labels: checkStringMap(d.Get("labels")), + PassthroughExtensions: expandPrivatecaCertificateTemplatePassthroughExtensions(d.Get("passthrough_extensions")), + PredefinedValues: expandPrivatecaCertificateTemplatePredefinedValues(d.Get("predefined_values")), + Project: dcl.String(project), + } + + id, err := replaceVarsForId(d, config, "projects/{{project}}/locations/{{location}}/certificateTemplates/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + createDirective := CreateDirective + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + billingProject := project + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + client := NewDCLPrivatecaClient(config, userAgent, billingProject) + res, err := client.ApplyCertificateTemplate(context.Background(), obj, createDirective...) + + if _, ok := err.(dcl.DiffAfterApplyError); ok { + log.Printf("[DEBUG] Diff after apply returned from the DCL: %s", err) + } else if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error creating CertificateTemplate: %s", err) + } + + log.Printf("[DEBUG] Finished creating CertificateTemplate %q: %#v", d.Id(), res) + + return resourcePrivatecaCertificateTemplateRead(d, meta) +} + +func resourcePrivatecaCertificateTemplateRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + project, err := getProject(d, config) + if err != nil { + return err + } + + obj := &privateca.CertificateTemplate{ + Location: dcl.String(d.Get("location").(string)), + Name: dcl.String(d.Get("name").(string)), + Description: dcl.String(d.Get("description").(string)), + IdentityConstraints: expandPrivatecaCertificateTemplateIdentityConstraints(d.Get("identity_constraints")), + Labels: checkStringMap(d.Get("labels")), + PassthroughExtensions: expandPrivatecaCertificateTemplatePassthroughExtensions(d.Get("passthrough_extensions")), + PredefinedValues: expandPrivatecaCertificateTemplatePredefinedValues(d.Get("predefined_values")), + Project: dcl.String(project), + } + + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + billingProject := project + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + client := NewDCLPrivatecaClient(config, userAgent, billingProject) + res, err := client.GetCertificateTemplate(context.Background(), obj) + if err != nil { + // Resource not found + d.SetId("") + return err + } + + if err = d.Set("location", res.Location); err != nil { + return fmt.Errorf("error setting location in state: %s", err) + } + if err = d.Set("name", res.Name); err != nil { + return fmt.Errorf("error setting name in state: %s", err) + } + if err = d.Set("description", res.Description); err != nil { + return fmt.Errorf("error setting description in state: %s", err) + } + if err = d.Set("identity_constraints", flattenPrivatecaCertificateTemplateIdentityConstraints(res.IdentityConstraints)); err != nil { + return fmt.Errorf("error setting identity_constraints in state: %s", err) + } + if err = d.Set("labels", res.Labels); err != nil { + return fmt.Errorf("error setting labels in state: %s", err) + } + if err = d.Set("passthrough_extensions", flattenPrivatecaCertificateTemplatePassthroughExtensions(res.PassthroughExtensions)); err != nil { + return fmt.Errorf("error setting passthrough_extensions in state: %s", err) + } + if err = d.Set("predefined_values", flattenPrivatecaCertificateTemplatePredefinedValues(res.PredefinedValues)); err != nil { + return fmt.Errorf("error setting predefined_values in state: %s", err) + } + if err = d.Set("project", res.Project); err != nil { + return fmt.Errorf("error setting project in state: %s", err) + } + if err = d.Set("create_time", res.CreateTime); err != nil { + return fmt.Errorf("error setting create_time in state: %s", err) + } + if err = d.Set("update_time", res.UpdateTime); err != nil { + return fmt.Errorf("error setting update_time in state: %s", err) + } + + return nil +} +func resourcePrivatecaCertificateTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + project, err := getProject(d, config) + if err != nil { + return err + } + + obj := &privateca.CertificateTemplate{ + Location: dcl.String(d.Get("location").(string)), + Name: dcl.String(d.Get("name").(string)), + Description: dcl.String(d.Get("description").(string)), + IdentityConstraints: expandPrivatecaCertificateTemplateIdentityConstraints(d.Get("identity_constraints")), + Labels: checkStringMap(d.Get("labels")), + PassthroughExtensions: expandPrivatecaCertificateTemplatePassthroughExtensions(d.Get("passthrough_extensions")), + PredefinedValues: expandPrivatecaCertificateTemplatePredefinedValues(d.Get("predefined_values")), + Project: dcl.String(project), + } + // Construct state hint from old values + old := &privateca.CertificateTemplate{ + Location: dcl.String(oldValue(d.GetChange("location")).(string)), + Name: dcl.String(oldValue(d.GetChange("name")).(string)), + Description: dcl.String(oldValue(d.GetChange("description")).(string)), + IdentityConstraints: expandPrivatecaCertificateTemplateIdentityConstraints(oldValue(d.GetChange("identity_constraints"))), + Labels: checkStringMap(oldValue(d.GetChange("labels"))), + PassthroughExtensions: expandPrivatecaCertificateTemplatePassthroughExtensions(oldValue(d.GetChange("passthrough_extensions"))), + PredefinedValues: expandPrivatecaCertificateTemplatePredefinedValues(oldValue(d.GetChange("predefined_values"))), + Project: dcl.StringOrNil(oldValue(d.GetChange("project")).(string)), + } + directive := UpdateDirective + directive = append(directive, dcl.WithStateHint(old)) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + client := NewDCLPrivatecaClient(config, userAgent, billingProject) + res, err := client.ApplyCertificateTemplate(context.Background(), obj, directive...) + + if _, ok := err.(dcl.DiffAfterApplyError); ok { + log.Printf("[DEBUG] Diff after apply returned from the DCL: %s", err) + } else if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error updating CertificateTemplate: %s", err) + } + + log.Printf("[DEBUG] Finished creating CertificateTemplate %q: %#v", d.Id(), res) + + return resourcePrivatecaCertificateTemplateRead(d, meta) +} + +func resourcePrivatecaCertificateTemplateDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + project, err := getProject(d, config) + if err != nil { + return err + } + + obj := &privateca.CertificateTemplate{ + Location: dcl.String(d.Get("location").(string)), + Name: dcl.String(d.Get("name").(string)), + Description: dcl.String(d.Get("description").(string)), + IdentityConstraints: expandPrivatecaCertificateTemplateIdentityConstraints(d.Get("identity_constraints")), + Labels: checkStringMap(d.Get("labels")), + PassthroughExtensions: expandPrivatecaCertificateTemplatePassthroughExtensions(d.Get("passthrough_extensions")), + PredefinedValues: expandPrivatecaCertificateTemplatePredefinedValues(d.Get("predefined_values")), + Project: dcl.String(project), + } + + log.Printf("[DEBUG] Deleting CertificateTemplate %q", d.Id()) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + billingProject := project + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + client := NewDCLPrivatecaClient(config, userAgent, billingProject) + if err := client.DeleteCertificateTemplate(context.Background(), obj); err != nil { + return fmt.Errorf("Error deleting CertificateTemplate: %s", err) + } + + log.Printf("[DEBUG] Finished deleting CertificateTemplate %q", d.Id()) + return nil +} + +func resourcePrivatecaCertificateTemplateImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{ + "projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/certificateTemplates/(?P<name>[^/]+)", + "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<name>[^/]+)", + "(?P<location>[^/]+)/(?P<name>[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVarsForId(d, config, "projects/{{project}}/locations/{{location}}/certificateTemplates/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func expandPrivatecaCertificateTemplateIdentityConstraints(o interface{}) *privateca.CertificateTemplateIdentityConstraints { + if o == nil { + return privateca.EmptyCertificateTemplateIdentityConstraints + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplateIdentityConstraints + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplateIdentityConstraints{ + AllowSubjectAltNamesPassthrough: dcl.Bool(obj["allow_subject_alt_names_passthrough"].(bool)), + AllowSubjectPassthrough: dcl.Bool(obj["allow_subject_passthrough"].(bool)), + CelExpression: expandPrivatecaCertificateTemplateIdentityConstraintsCelExpression(obj["cel_expression"]), + } +} + +func flattenPrivatecaCertificateTemplateIdentityConstraints(obj *privateca.CertificateTemplateIdentityConstraints) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "allow_subject_alt_names_passthrough": obj.AllowSubjectAltNamesPassthrough, + "allow_subject_passthrough": obj.AllowSubjectPassthrough, + "cel_expression": flattenPrivatecaCertificateTemplateIdentityConstraintsCelExpression(obj.CelExpression), + } + + return []interface{}{transformed} + +} + +func expandPrivatecaCertificateTemplateIdentityConstraintsCelExpression(o interface{}) *privateca.CertificateTemplateIdentityConstraintsCelExpression { + if o == nil { + return privateca.EmptyCertificateTemplateIdentityConstraintsCelExpression + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplateIdentityConstraintsCelExpression + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplateIdentityConstraintsCelExpression{ + Description: dcl.String(obj["description"].(string)), + Expression: dcl.String(obj["expression"].(string)), + Location: dcl.String(obj["location"].(string)), + Title: dcl.String(obj["title"].(string)), + } +} + +func flattenPrivatecaCertificateTemplateIdentityConstraintsCelExpression(obj *privateca.CertificateTemplateIdentityConstraintsCelExpression) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "description": obj.Description, + "expression": obj.Expression, + "location": obj.Location, + "title": obj.Title, + } + + return []interface{}{transformed} + +} + +func expandPrivatecaCertificateTemplatePassthroughExtensions(o interface{}) *privateca.CertificateTemplatePassthroughExtensions { + if o == nil { + return privateca.EmptyCertificateTemplatePassthroughExtensions + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePassthroughExtensions + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePassthroughExtensions{ + AdditionalExtensions: expandPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensionsArray(obj["additional_extensions"]), + KnownExtensions: expandPrivatecaCertificateTemplatePassthroughExtensionsKnownExtensionsArray(obj["known_extensions"]), + } +} + +func flattenPrivatecaCertificateTemplatePassthroughExtensions(obj *privateca.CertificateTemplatePassthroughExtensions) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "additional_extensions": flattenPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensionsArray(obj.AdditionalExtensions), + "known_extensions": flattenPrivatecaCertificateTemplatePassthroughExtensionsKnownExtensionsArray(obj.KnownExtensions), + } + + return []interface{}{transformed} + +} +func expandPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensionsArray(o interface{}) []privateca.CertificateTemplatePassthroughExtensionsAdditionalExtensions { + if o == nil { + return nil + } + + objs := o.([]interface{}) + if len(objs) == 0 { + return nil + } + + items := make([]privateca.CertificateTemplatePassthroughExtensionsAdditionalExtensions, 0, len(objs)) + for _, item := range objs { + i := expandPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensions(item) + items = append(items, *i) + } + + return items +} + +func expandPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensions(o interface{}) *privateca.CertificateTemplatePassthroughExtensionsAdditionalExtensions { + if o == nil { + return privateca.EmptyCertificateTemplatePassthroughExtensionsAdditionalExtensions + } + + obj := o.(map[string]interface{}) + return &privateca.CertificateTemplatePassthroughExtensionsAdditionalExtensions{ + ObjectIdPath: expandIntegerArray(obj["object_id_path"]), + } +} + +func flattenPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensionsArray(objs []privateca.CertificateTemplatePassthroughExtensionsAdditionalExtensions) []interface{} { + if objs == nil { + return nil + } + + items := []interface{}{} + for _, item := range objs { + i := flattenPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensions(&item) + items = append(items, i) + } + + return items +} + +func flattenPrivatecaCertificateTemplatePassthroughExtensionsAdditionalExtensions(obj *privateca.CertificateTemplatePassthroughExtensionsAdditionalExtensions) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "object_id_path": obj.ObjectIdPath, + } + + return transformed + +} + +func expandPrivatecaCertificateTemplatePredefinedValues(o interface{}) *privateca.CertificateTemplatePredefinedValues { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValues + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePredefinedValues + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValues{ + AdditionalExtensions: expandPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsArray(obj["additional_extensions"]), + AiaOcspServers: expandStringArray(obj["aia_ocsp_servers"]), + CaOptions: expandPrivatecaCertificateTemplatePredefinedValuesCaOptions(obj["ca_options"]), + KeyUsage: expandPrivatecaCertificateTemplatePredefinedValuesKeyUsage(obj["key_usage"]), + PolicyIds: expandPrivatecaCertificateTemplatePredefinedValuesPolicyIdsArray(obj["policy_ids"]), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValues(obj *privateca.CertificateTemplatePredefinedValues) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "additional_extensions": flattenPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsArray(obj.AdditionalExtensions), + "aia_ocsp_servers": obj.AiaOcspServers, + "ca_options": flattenPrivatecaCertificateTemplatePredefinedValuesCaOptions(obj.CaOptions), + "key_usage": flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsage(obj.KeyUsage), + "policy_ids": flattenPrivatecaCertificateTemplatePredefinedValuesPolicyIdsArray(obj.PolicyIds), + } + + return []interface{}{transformed} + +} +func expandPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsArray(o interface{}) []privateca.CertificateTemplatePredefinedValuesAdditionalExtensions { + if o == nil { + return nil + } + + objs := o.([]interface{}) + if len(objs) == 0 { + return nil + } + + items := make([]privateca.CertificateTemplatePredefinedValuesAdditionalExtensions, 0, len(objs)) + for _, item := range objs { + i := expandPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensions(item) + items = append(items, *i) + } + + return items +} + +func expandPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensions(o interface{}) *privateca.CertificateTemplatePredefinedValuesAdditionalExtensions { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesAdditionalExtensions + } + + obj := o.(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesAdditionalExtensions{ + ObjectId: expandPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsObjectId(obj["object_id"]), + Value: dcl.String(obj["value"].(string)), + Critical: dcl.Bool(obj["critical"].(bool)), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsArray(objs []privateca.CertificateTemplatePredefinedValuesAdditionalExtensions) []interface{} { + if objs == nil { + return nil + } + + items := []interface{}{} + for _, item := range objs { + i := flattenPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensions(&item) + items = append(items, i) + } + + return items +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensions(obj *privateca.CertificateTemplatePredefinedValuesAdditionalExtensions) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "object_id": flattenPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsObjectId(obj.ObjectId), + "value": obj.Value, + "critical": obj.Critical, + } + + return transformed + +} + +func expandPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsObjectId(o interface{}) *privateca.CertificateTemplatePredefinedValuesAdditionalExtensionsObjectId { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesAdditionalExtensionsObjectId + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePredefinedValuesAdditionalExtensionsObjectId + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesAdditionalExtensionsObjectId{ + ObjectIdPath: expandIntegerArray(obj["object_id_path"]), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesAdditionalExtensionsObjectId(obj *privateca.CertificateTemplatePredefinedValuesAdditionalExtensionsObjectId) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "object_id_path": obj.ObjectIdPath, + } + + return []interface{}{transformed} + +} + +func expandPrivatecaCertificateTemplatePredefinedValuesCaOptions(o interface{}) *privateca.CertificateTemplatePredefinedValuesCaOptions { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesCaOptions + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePredefinedValuesCaOptions + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesCaOptions{ + IsCa: dcl.Bool(obj["is_ca"].(bool)), + MaxIssuerPathLength: dcl.Int64(int64(obj["max_issuer_path_length"].(int))), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesCaOptions(obj *privateca.CertificateTemplatePredefinedValuesCaOptions) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "is_ca": obj.IsCa, + "max_issuer_path_length": obj.MaxIssuerPathLength, + } + + return []interface{}{transformed} + +} + +func expandPrivatecaCertificateTemplatePredefinedValuesKeyUsage(o interface{}) *privateca.CertificateTemplatePredefinedValuesKeyUsage { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsage + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsage + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesKeyUsage{ + BaseKeyUsage: expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage(obj["base_key_usage"]), + ExtendedKeyUsage: expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage(obj["extended_key_usage"]), + UnknownExtendedKeyUsages: expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsagesArray(obj["unknown_extended_key_usages"]), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsage(obj *privateca.CertificateTemplatePredefinedValuesKeyUsage) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "base_key_usage": flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage(obj.BaseKeyUsage), + "extended_key_usage": flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage(obj.ExtendedKeyUsage), + "unknown_extended_key_usages": flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsagesArray(obj.UnknownExtendedKeyUsages), + } + + return []interface{}{transformed} + +} + +func expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage(o interface{}) *privateca.CertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage{ + CertSign: dcl.Bool(obj["cert_sign"].(bool)), + ContentCommitment: dcl.Bool(obj["content_commitment"].(bool)), + CrlSign: dcl.Bool(obj["crl_sign"].(bool)), + DataEncipherment: dcl.Bool(obj["data_encipherment"].(bool)), + DecipherOnly: dcl.Bool(obj["decipher_only"].(bool)), + DigitalSignature: dcl.Bool(obj["digital_signature"].(bool)), + EncipherOnly: dcl.Bool(obj["encipher_only"].(bool)), + KeyAgreement: dcl.Bool(obj["key_agreement"].(bool)), + KeyEncipherment: dcl.Bool(obj["key_encipherment"].(bool)), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage(obj *privateca.CertificateTemplatePredefinedValuesKeyUsageBaseKeyUsage) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "cert_sign": obj.CertSign, + "content_commitment": obj.ContentCommitment, + "crl_sign": obj.CrlSign, + "data_encipherment": obj.DataEncipherment, + "decipher_only": obj.DecipherOnly, + "digital_signature": obj.DigitalSignature, + "encipher_only": obj.EncipherOnly, + "key_agreement": obj.KeyAgreement, + "key_encipherment": obj.KeyEncipherment, + } + + return []interface{}{transformed} + +} + +func expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage(o interface{}) *privateca.CertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage + } + objArr := o.([]interface{}) + if len(objArr) == 0 { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage + } + obj := objArr[0].(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage{ + ClientAuth: dcl.Bool(obj["client_auth"].(bool)), + CodeSigning: dcl.Bool(obj["code_signing"].(bool)), + EmailProtection: dcl.Bool(obj["email_protection"].(bool)), + OcspSigning: dcl.Bool(obj["ocsp_signing"].(bool)), + ServerAuth: dcl.Bool(obj["server_auth"].(bool)), + TimeStamping: dcl.Bool(obj["time_stamping"].(bool)), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage(obj *privateca.CertificateTemplatePredefinedValuesKeyUsageExtendedKeyUsage) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "client_auth": obj.ClientAuth, + "code_signing": obj.CodeSigning, + "email_protection": obj.EmailProtection, + "ocsp_signing": obj.OcspSigning, + "server_auth": obj.ServerAuth, + "time_stamping": obj.TimeStamping, + } + + return []interface{}{transformed} + +} +func expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsagesArray(o interface{}) []privateca.CertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages { + if o == nil { + return nil + } + + objs := o.([]interface{}) + if len(objs) == 0 { + return nil + } + + items := make([]privateca.CertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages, 0, len(objs)) + for _, item := range objs { + i := expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages(item) + items = append(items, *i) + } + + return items +} + +func expandPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages(o interface{}) *privateca.CertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages + } + + obj := o.(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages{ + ObjectIdPath: expandIntegerArray(obj["object_id_path"]), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsagesArray(objs []privateca.CertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages) []interface{} { + if objs == nil { + return nil + } + + items := []interface{}{} + for _, item := range objs { + i := flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages(&item) + items = append(items, i) + } + + return items +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages(obj *privateca.CertificateTemplatePredefinedValuesKeyUsageUnknownExtendedKeyUsages) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "object_id_path": obj.ObjectIdPath, + } + + return transformed + +} +func expandPrivatecaCertificateTemplatePredefinedValuesPolicyIdsArray(o interface{}) []privateca.CertificateTemplatePredefinedValuesPolicyIds { + if o == nil { + return nil + } + + objs := o.([]interface{}) + if len(objs) == 0 { + return nil + } + + items := make([]privateca.CertificateTemplatePredefinedValuesPolicyIds, 0, len(objs)) + for _, item := range objs { + i := expandPrivatecaCertificateTemplatePredefinedValuesPolicyIds(item) + items = append(items, *i) + } + + return items +} + +func expandPrivatecaCertificateTemplatePredefinedValuesPolicyIds(o interface{}) *privateca.CertificateTemplatePredefinedValuesPolicyIds { + if o == nil { + return privateca.EmptyCertificateTemplatePredefinedValuesPolicyIds + } + + obj := o.(map[string]interface{}) + return &privateca.CertificateTemplatePredefinedValuesPolicyIds{ + ObjectIdPath: expandIntegerArray(obj["object_id_path"]), + } +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesPolicyIdsArray(objs []privateca.CertificateTemplatePredefinedValuesPolicyIds) []interface{} { + if objs == nil { + return nil + } + + items := []interface{}{} + for _, item := range objs { + i := flattenPrivatecaCertificateTemplatePredefinedValuesPolicyIds(&item) + items = append(items, i) + } + + return items +} + +func flattenPrivatecaCertificateTemplatePredefinedValuesPolicyIds(obj *privateca.CertificateTemplatePredefinedValuesPolicyIds) interface{} { + if obj == nil || obj.Empty() { + return nil + } + transformed := map[string]interface{}{ + "object_id_path": obj.ObjectIdPath, + } + + return transformed + +} +func flattenPrivatecaCertificateTemplatePassthroughExtensionsKnownExtensionsArray(obj []privateca.CertificateTemplatePassthroughExtensionsKnownExtensionsEnum) interface{} { + if obj == nil { + return nil + } + items := []string{} + for _, item := range obj { + items = append(items, string(item)) + } + return items +} + +func expandPrivatecaCertificateTemplatePassthroughExtensionsKnownExtensionsArray(o interface{}) []privateca.CertificateTemplatePassthroughExtensionsKnownExtensionsEnum { + objs := o.([]interface{}) + items := make([]privateca.CertificateTemplatePassthroughExtensionsKnownExtensionsEnum, 0, len(objs)) + for _, item := range objs { + i := privateca.CertificateTemplatePassthroughExtensionsKnownExtensionsEnumRef(item.(string)) + items = append(items, *i) + } + return items +} diff --git a/google/resource_privateca_certificate_template_generated_test.go b/google/resource_privateca_certificate_template_generated_test.go new file mode 100644 index 00000000000..34018c36752 --- /dev/null +++ b/google/resource_privateca_certificate_template_generated_test.go @@ -0,0 +1,265 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: DCL *** +// +// ---------------------------------------------------------------------------- +// +// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules) +// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library). +// Changes will need to be made to the DCL or Magic Modules instead of here. +// +// We are not currently able to accept contributions to this file. If changes +// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "context" + "fmt" + dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" + privateca "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/privateca" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "strings" + "testing" +) + +func TestAccPrivatecaCertificateTemplate_BasicCertificateTemplate(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": getTestProjectFromEnv(), + "region": getTestRegionFromEnv(), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckPrivatecaCertificateTemplateDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccPrivatecaCertificateTemplate_BasicCertificateTemplate(context), + }, + { + ResourceName: "google_privateca_certificate_template.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"predefined_values.0.key_usage.0.extended_key_usage"}, + }, + { + Config: testAccPrivatecaCertificateTemplate_BasicCertificateTemplateUpdate0(context), + }, + { + ResourceName: "google_privateca_certificate_template.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"predefined_values.0.key_usage.0.extended_key_usage"}, + }, + }, + }) +} + +func testAccPrivatecaCertificateTemplate_BasicCertificateTemplate(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "primary" { + location = "%{region}" + name = "tf-test-template-test%{random_suffix}" + description = "An updated sample certificate template" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } + + passthrough_extensions { + additional_extensions { + object_id_path = [1, 6] + } + + known_extensions = ["EXTENDED_KEY_USAGE"] + } + + predefined_values { + additional_extensions { + object_id { + object_id_path = [1, 6] + } + + value = "c3RyaW5nCg==" + critical = true + } + + aia_ocsp_servers = ["string"] + + ca_options { + is_ca = false + max_issuer_path_length = 6 + } + + key_usage { + base_key_usage { + cert_sign = false + content_commitment = true + crl_sign = false + data_encipherment = true + decipher_only = true + digital_signature = true + encipher_only = true + key_agreement = true + key_encipherment = true + } + + extended_key_usage { + client_auth = true + code_signing = true + email_protection = true + ocsp_signing = true + server_auth = true + time_stamping = true + } + + unknown_extended_key_usages { + object_id_path = [1, 6] + } + } + + policy_ids { + object_id_path = [1, 6] + } + } + + project = "%{project_name}" +} + + +`, context) +} + +func testAccPrivatecaCertificateTemplate_BasicCertificateTemplateUpdate0(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "primary" { + location = "%{region}" + name = "tf-test-template-test%{random_suffix}" + description = "A sample certificate template" + + identity_constraints { + allow_subject_alt_names_passthrough = false + allow_subject_passthrough = false + + cel_expression { + description = "Always false" + expression = "false" + location = "update.certificate_template.json" + title = "New sample expression" + } + } + + passthrough_extensions { + additional_extensions { + object_id_path = [1, 7] + } + + known_extensions = ["BASE_KEY_USAGE"] + } + + predefined_values { + additional_extensions { + object_id { + object_id_path = [1, 7] + } + + value = "bmV3LXN0cmluZw==" + critical = false + } + + aia_ocsp_servers = ["new-string"] + + ca_options { + is_ca = true + max_issuer_path_length = 7 + } + + key_usage { + base_key_usage { + cert_sign = true + content_commitment = false + crl_sign = true + data_encipherment = false + decipher_only = false + digital_signature = false + encipher_only = false + key_agreement = false + key_encipherment = false + } + + extended_key_usage { + client_auth = false + code_signing = false + email_protection = false + ocsp_signing = false + server_auth = false + time_stamping = false + } + + unknown_extended_key_usages { + object_id_path = [1, 7] + } + } + + policy_ids { + object_id_path = [1, 7] + } + } + + project = "%{project_name}" +} + + +`, context) +} + +func testAccCheckPrivatecaCertificateTemplateDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "rs.google_privateca_certificate_template" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := googleProviderConfig(t) + + billingProject := "" + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + obj := &privateca.CertificateTemplate{ + Location: dcl.String(rs.Primary.Attributes["location"]), + Name: dcl.String(rs.Primary.Attributes["name"]), + Description: dcl.String(rs.Primary.Attributes["description"]), + Project: dcl.StringOrNil(rs.Primary.Attributes["project"]), + CreateTime: dcl.StringOrNil(rs.Primary.Attributes["create_time"]), + UpdateTime: dcl.StringOrNil(rs.Primary.Attributes["update_time"]), + } + + client := NewDCLPrivatecaClient(config, config.userAgent, billingProject) + _, err := client.GetCertificateTemplate(context.Background(), obj) + if err == nil { + return fmt.Errorf("google_privateca_certificate_template still exists %v", obj) + } + } + return nil + } +} diff --git a/google/resource_privateca_certificate_template_sweeper_test.go b/google/resource_privateca_certificate_template_sweeper_test.go new file mode 100644 index 00000000000..96df6d1f16f --- /dev/null +++ b/google/resource_privateca_certificate_template_sweeper_test.go @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: DCL *** +// +// ---------------------------------------------------------------------------- +// +// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules) +// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library). +// Changes will need to be made to the DCL or Magic Modules instead of here. +// +// We are not currently able to accept contributions to this file. If changes +// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "context" + "log" + "testing" + + privateca "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/privateca" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func init() { + resource.AddTestSweepers("PrivatecaCertificate_template", &resource.Sweeper{ + Name: "PrivatecaCertificate_template", + F: testSweepPrivatecaCertificate_template, + }) +} + +func testSweepPrivatecaCertificate_template(region string) error { + resourceName := "PrivatecaCertificate_template" + log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) + + config, err := sharedConfigForRegion(region) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) + return err + } + + err = config.LoadAndValidate(context.Background()) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) + return err + } + + t := &testing.T{} + billingId := getTestBillingAccountFromEnv(t) + + // Setup variables to be used for Delete arguments. + d := map[string]string{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + "billing_account": billingId, + } + + client := NewDCLPrivatecaClient(config, config.userAgent, "") + err = client.DeleteAllCertificateTemplate(context.Background(), d["project"], d["location"], isDeletablePrivatecaCertificate_template) + if err != nil { + return err + } + return nil +} + +func isDeletablePrivatecaCertificate_template(r *privateca.CertificateTemplate) bool { + return isSweepableTestResource(*r.Name) +} diff --git a/website/docs/r/privateca_certificate_template.html.markdown b/website/docs/r/privateca_certificate_template.html.markdown new file mode 100644 index 00000000000..fabf3baccf1 --- /dev/null +++ b/website/docs/r/privateca_certificate_template.html.markdown @@ -0,0 +1,374 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: DCL *** +# +# ---------------------------------------------------------------------------- +# +# This file is managed by Magic Modules (https:#github.com/GoogleCloudPlatform/magic-modules) +# and is based on the DCL (https:#github.com/GoogleCloudPlatform/declarative-resource-client-library). +# Changes will need to be made to the DCL or Magic Modules instead of here. +# +# We are not currently able to accept contributions to this file. If changes +# are required, please file an issue at https:#github.com/hashicorp/terraform-provider-google/issues/new/choose +# +# ---------------------------------------------------------------------------- +subcategory: "Privateca" +layout: "google" +page_title: "Google: google_privateca_certificate_template" +sidebar_current: "docs-google-privateca-certificate-template" +description: |- + +--- + +# google\_privateca\_certificate\_template + + +## Example Usage - basic_certificate_template +An example of a basic privateca certificate template +```hcl +resource "google_privateca_certificate_template" "primary" { + location = "us-west1" + name = "template-test" + description = "An updated sample certificate template" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } + + passthrough_extensions { + additional_extensions { + object_id_path = [1, 6] + } + + known_extensions = ["EXTENDED_KEY_USAGE"] + } + + predefined_values { + additional_extensions { + object_id { + object_id_path = [1, 6] + } + + value = "c3RyaW5nCg==" + critical = true + } + + aia_ocsp_servers = ["string"] + + ca_options { + is_ca = false + max_issuer_path_length = 6 + } + + key_usage { + base_key_usage { + cert_sign = false + content_commitment = true + crl_sign = false + data_encipherment = true + decipher_only = true + digital_signature = true + encipher_only = true + key_agreement = true + key_encipherment = true + } + + extended_key_usage { + client_auth = true + code_signing = true + email_protection = true + ocsp_signing = true + server_auth = true + time_stamping = true + } + + unknown_extended_key_usages { + object_id_path = [1, 6] + } + } + + policy_ids { + object_id_path = [1, 6] + } + } + + project = "my-project-name" +} + + +``` + +## Argument Reference + +The following arguments are supported: + +* `location` - + (Required) + The location for the resource + +* `name` - + (Required) + The resource name for this CertificateTemplate in the format `projects/*/locations/*/certificateTemplates/*`. + + + +The `object_id` block supports: + +* `object_id_path` - + (Required) + Required. The parts of an OID path. The most significant parts of the path come first. + +- - - + +* `description` - + (Optional) + Optional. A human-readable description of scenarios this template is intended for. + +* `identity_constraints` - + (Optional) + Optional. Describes constraints on identities that may be appear in Certificates issued using this template. If this is omitted, then this template will not add restrictions on a certificate's identity. + +* `labels` - + (Optional) + Optional. Labels with user-defined metadata. + +* `passthrough_extensions` - + (Optional) + Optional. Describes the set of X.509 extensions that may appear in a Certificate issued using this CertificateTemplate. If a certificate request sets extensions that don't appear in the passthrough_extensions, those extensions will be dropped. If the issuing CaPool's IssuancePolicy defines baseline_values that don't appear here, the certificate issuance request will fail. If this is omitted, then this template will not add restrictions on a certificate's X.509 extensions. These constraints do not apply to X.509 extensions set in this CertificateTemplate's predefined_values. + +* `predefined_values` - + (Optional) + Optional. A set of X.509 values that will be applied to all issued certificates that use this template. If the certificate request includes conflicting values for the same properties, they will be overwritten by the values defined here. If the issuing CaPool's IssuancePolicy defines conflicting baseline_values for the same properties, the certificate issuance request will fail. + +* `project` - + (Optional) + The project for the resource + + + +The `identity_constraints` block supports: + +* `allow_subject_alt_names_passthrough` - + (Required) + Required. If this is true, the SubjectAltNames extension may be copied from a certificate request into the signed certificate. Otherwise, the requested SubjectAltNames will be discarded. + +* `allow_subject_passthrough` - + (Required) + Required. If this is true, the Subject field may be copied from a certificate request into the signed certificate. Otherwise, the requested Subject will be discarded. + +* `cel_expression` - + (Optional) + Optional. A CEL expression that may be used to validate the resolved X.509 Subject and/or Subject Alternative Name before a certificate is signed. To see the full allowed syntax and some examples, see https://cloud.google.com/certificate-authority-service/docs/using-cel + +The `cel_expression` block supports: + +* `description` - + (Optional) + Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. + +* `expression` - + (Optional) + Textual representation of an expression in Common Expression Language syntax. + +* `location` - + (Optional) + Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file. + +* `title` - + (Optional) + Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression. + +The `passthrough_extensions` block supports: + +* `additional_extensions` - + (Optional) + Optional. A set of ObjectIds identifying custom X.509 extensions. Will be combined with known_extensions to determine the full set of X.509 extensions. + +* `known_extensions` - + (Optional) + Optional. A set of named X.509 extensions. Will be combined with additional_extensions to determine the full set of X.509 extensions. + +The `additional_extensions` block supports: + +* `object_id_path` - + (Required) + Required. The parts of an OID path. The most significant parts of the path come first. + +The `predefined_values` block supports: + +* `additional_extensions` - + (Optional) + Optional. Describes custom X.509 extensions. + +* `aia_ocsp_servers` - + (Optional) + Optional. Describes Online Certificate Status Protocol (OCSP) endpoint addresses that appear in the "Authority Information Access" extension in the certificate. + +* `ca_options` - + (Optional) + Optional. Describes options in this X509Parameters that are relevant in a CA certificate. + +* `key_usage` - + (Optional) + Optional. Indicates the intended use for keys that correspond to a certificate. + +* `policy_ids` - + (Optional) + Optional. Describes the X.509 certificate policy object identifiers, per https://tools.ietf.org/html/rfc5280#section-4.2.1.4. + +The `additional_extensions` block supports: + +* `critical` - + (Optional) + Optional. Indicates whether or not this extension is critical (i.e., if the client does not know how to handle this extension, the client should consider this to be an error). + +* `object_id` - + (Required) + Required. The OID for this X.509 extension. + +* `value` - + (Required) + Required. The value of this X.509 extension. + +The `ca_options` block supports: + +* `is_ca` - + (Optional) + Optional. Refers to the "CA" X.509 extension, which is a boolean value. When this value is missing, the extension will be omitted from the CA certificate. + +* `max_issuer_path_length` - + (Optional) + Optional. Refers to the path length restriction X.509 extension. For a CA certificate, this value describes the depth of subordinate CA certificates that are allowed. If this value is less than 0, the request will fail. If this value is missing, the max path length will be omitted from the CA certificate. + +The `key_usage` block supports: + +* `base_key_usage` - + (Optional) + Describes high-level ways in which a key may be used. + +* `extended_key_usage` - + (Optional) + Detailed scenarios in which a key may be used. + +* `unknown_extended_key_usages` - + (Optional) + Used to describe extended key usages that are not listed in the KeyUsage.ExtendedKeyUsageOptions message. + +The `base_key_usage` block supports: + +* `cert_sign` - + (Optional) + The key may be used to sign certificates. + +* `content_commitment` - + (Optional) + The key may be used for cryptographic commitments. Note that this may also be referred to as "non-repudiation". + +* `crl_sign` - + (Optional) + The key may be used sign certificate revocation lists. + +* `data_encipherment` - + (Optional) + The key may be used to encipher data. + +* `decipher_only` - + (Optional) + The key may be used to decipher only. + +* `digital_signature` - + (Optional) + The key may be used for digital signatures. + +* `encipher_only` - + (Optional) + The key may be used to encipher only. + +* `key_agreement` - + (Optional) + The key may be used in a key agreement protocol. + +* `key_encipherment` - + (Optional) + The key may be used to encipher other keys. + +The `extended_key_usage` block supports: + +* `client_auth` - + (Optional) + Corresponds to OID 1.3.6.1.5.5.7.3.2. Officially described as "TLS WWW client authentication", though regularly used for non-WWW TLS. + +* `code_signing` - + (Optional) + Corresponds to OID 1.3.6.1.5.5.7.3.3. Officially described as "Signing of downloadable executable code client authentication". + +* `email_protection` - + (Optional) + Corresponds to OID 1.3.6.1.5.5.7.3.4. Officially described as "Email protection". + +* `ocsp_signing` - + (Optional) + Corresponds to OID 1.3.6.1.5.5.7.3.9. Officially described as "Signing OCSP responses". + +* `server_auth` - + (Optional) + Corresponds to OID 1.3.6.1.5.5.7.3.1. Officially described as "TLS WWW server authentication", though regularly used for non-WWW TLS. + +* `time_stamping` - + (Optional) + Corresponds to OID 1.3.6.1.5.5.7.3.8. Officially described as "Binding the hash of an object to a time". + +The `unknown_extended_key_usages` block supports: + +* `object_id_path` - + (Required) + Required. The parts of an OID path. The most significant parts of the path come first. + +The `policy_ids` block supports: + +* `object_id_path` - + (Required) + Required. The parts of an OID path. The most significant parts of the path come first. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/certificateTemplates/{{name}}` + +* `create_time` - + Output only. The time at which this CertificateTemplate was created. + +* `update_time` - + Output only. The time at which this CertificateTemplate was updated. + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 10 minutes. +- `update` - Default is 10 minutes. +- `delete` - Default is 10 minutes. + +## Import + +CertificateTemplate can be imported using any of these accepted formats: + +``` +$ terraform import google_privateca_certificate_template.default projects/{{project}}/locations/{{location}}/certificateTemplates/{{name}} +$ terraform import google_privateca_certificate_template.default {{project}}/{{location}}/{{name}} +$ terraform import google_privateca_certificate_template.default {{location}}/{{name}} +``` + + + diff --git a/website/google.erb b/website/google.erb index 4578173664a..ed191ce9bb2 100644 --- a/website/google.erb +++ b/website/google.erb @@ -2807,6 +2807,22 @@ </ul> </li> + <li> + <a href="#">Privateca</a> + <ul class="nav"> + <li> + <a href="#">Resources</a> + <ul class="nav nav-auto-expand"> + + <li> + <a href="/docs/providers/google/r/privateca_certificate_template.html">google_privateca_certificate_template</a> + </li> + + </ul> + </li> + </ul> + </li> + <li> <a href="#">Resource Manager</a> <ul class="nav">