Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integrations product. Create Client resource. #7129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10186.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
google_integrations_client
```
1 change: 1 addition & 0 deletions google-beta/fwmodels/provider_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type ProviderModel struct {
IapCustomEndpoint types.String `tfsdk:"iap_custom_endpoint"`
IdentityPlatformCustomEndpoint types.String `tfsdk:"identity_platform_custom_endpoint"`
IntegrationConnectorsCustomEndpoint types.String `tfsdk:"integration_connectors_custom_endpoint"`
IntegrationsCustomEndpoint types.String `tfsdk:"integrations_custom_endpoint"`
KMSCustomEndpoint types.String `tfsdk:"kms_custom_endpoint"`
LoggingCustomEndpoint types.String `tfsdk:"logging_custom_endpoint"`
LookerCustomEndpoint types.String `tfsdk:"looker_custom_endpoint"`
Expand Down
6 changes: 6 additions & 0 deletions google-beta/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
transport_tpg.CustomEndpointValidator(),
},
},
"integrations_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
transport_tpg.CustomEndpointValidator(),
},
},
"kms_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
10 changes: 10 additions & 0 deletions google-beta/fwtransport/framework_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type FrameworkProviderConfig struct {
IapBasePath string
IdentityPlatformBasePath string
IntegrationConnectorsBasePath string
IntegrationsBasePath string
KMSBasePath string
LoggingBasePath string
LookerBasePath string
Expand Down Expand Up @@ -298,6 +299,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.IapBasePath = data.IapCustomEndpoint.ValueString()
p.IdentityPlatformBasePath = data.IdentityPlatformCustomEndpoint.ValueString()
p.IntegrationConnectorsBasePath = data.IntegrationConnectorsCustomEndpoint.ValueString()
p.IntegrationsBasePath = data.IntegrationsCustomEndpoint.ValueString()
p.KMSBasePath = data.KMSCustomEndpoint.ValueString()
p.LoggingBasePath = data.LoggingCustomEndpoint.ValueString()
p.LookerBasePath = data.LookerCustomEndpoint.ValueString()
Expand Down Expand Up @@ -1119,6 +1121,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
data.IntegrationConnectorsCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.IntegrationsCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_INTEGRATIONS_CUSTOM_ENDPOINT",
}, transport_tpg.DefaultBasePaths[transport_tpg.IntegrationsBasePathKey])
if customEndpoint != nil {
data.IntegrationsCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.KMSCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_KMS_CUSTOM_ENDPOINT",
Expand Down
6 changes: 6 additions & 0 deletions google-beta/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ func Provider() *schema.Provider {
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"integrations_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"kms_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1076,6 +1081,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.IapBasePath = d.Get("iap_custom_endpoint").(string)
config.IdentityPlatformBasePath = d.Get("identity_platform_custom_endpoint").(string)
config.IntegrationConnectorsBasePath = d.Get("integration_connectors_custom_endpoint").(string)
config.IntegrationsBasePath = d.Get("integrations_custom_endpoint").(string)
config.KMSBasePath = d.Get("kms_custom_endpoint").(string)
config.LoggingBasePath = d.Get("logging_custom_endpoint").(string)
config.LookerBasePath = d.Get("looker_custom_endpoint").(string)
Expand Down
6 changes: 4 additions & 2 deletions google-beta/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import (
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/iap"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/identityplatform"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/integrationconnectors"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/integrations"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/kms"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/logging"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/looker"
Expand Down Expand Up @@ -439,9 +440,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 454
// Generated resources: 455
// Generated IAM resources: 267
// Total generated resources: 721
// Total generated resources: 722
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -949,6 +950,7 @@ var generatedResources = map[string]*schema.Resource{
"google_identity_platform_tenant_oauth_idp_config": identityplatform.ResourceIdentityPlatformTenantOauthIdpConfig(),
"google_integration_connectors_connection": integrationconnectors.ResourceIntegrationConnectorsConnection(),
"google_integration_connectors_endpoint_attachment": integrationconnectors.ResourceIntegrationConnectorsEndpointAttachment(),
"google_integrations_client": integrations.ResourceIntegrationsClient(),
"google_kms_crypto_key": kms.ResourceKMSCryptoKey(),
"google_kms_crypto_key_version": kms.ResourceKMSCryptoKeyVersion(),
"google_kms_ekm_connection": kms.ResourceKMSEkmConnection(),
Expand Down
287 changes: 287 additions & 0 deletions google-beta/services/integrations/resource_integrations_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package integrations

import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func ResourceIntegrationsClient() *schema.Resource {
return &schema.Resource{
Create: resourceIntegrationsClientCreate,
Read: resourceIntegrationsClientRead,
Delete: resourceIntegrationsClientDelete,

Importer: &schema.ResourceImporter{
State: resourceIntegrationsClientImport,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},

CustomizeDiff: customdiff.All(
tpgresource.DefaultProviderProject,
),

Schema: map[string]*schema.Schema{
"location": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Location in which client needs to be provisioned.`,
},
"cloud_kms_config": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Cloud KMS config for AuthModule to encrypt/decrypt credentials.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `A Cloud KMS key is a named object containing one or more key versions, along
with metadata for the key. A key exists on exactly one key ring tied to a
specific location.`,
},
"kms_location": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Location name of the key ring, e.g. "us-west1".`,
},
"kms_ring": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `A key ring organizes keys in a specific Google Cloud location and allows you to
manage access control on groups of keys. A key ring's name does not need to be
unique across a Google Cloud project, but must be unique within a given location.`,
},
"key_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Each version of a key contains key material used for encryption or signing.
A key's version is represented by an integer, starting at 1. To decrypt data
or verify a signature, you must use the same key version that was used to
encrypt or sign the data.`,
},
"kms_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The Google Cloud project id of the project where the kms key stored. If empty,
the kms key is stored at the same project as customer's project and ecrypted
with CMEK, otherwise, the kms key is stored in the tenant project and
encrypted with GMEK.`,
},
},
},
},
"create_sample_workflows": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `Indicates if sample workflow should be created along with provisioning.`,
},
"provision_gmek": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `Indicates provision with GMEK or CMEK.`,
},
"run_as_service_account": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `User input run-as service account, if empty, will bring up a new default service account.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
UseJSONNumber: true,
}
}

func resourceIntegrationsClientCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}

obj := make(map[string]interface{})

lockName, err := tpgresource.ReplaceVars(d, config, "Client/{{location}}")
if err != nil {
return err
}
transport_tpg.MutexStore.Lock(lockName)
defer transport_tpg.MutexStore.Unlock(lockName)

url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationsBasePath}}projects/{{project}}/locations/{{location}}/clients:provision")
if err != nil {
return err
}

log.Printf("[DEBUG] Creating new Client: %#v", obj)
billingProject := ""

project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Client: %s", err)
}
billingProject = project

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}

res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutCreate),
})
if err != nil {
return fmt.Errorf("Error creating Client: %s", err)
}

// Store the ID now
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/clients")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

log.Printf("[DEBUG] Finished creating Client %q: %#v", d.Id(), res)

return resourceIntegrationsClientRead(d, meta)
}

func resourceIntegrationsClientRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationsBasePath}}projects/{{project}}/locations/{{location}}/clients")
if err != nil {
return err
}

billingProject := ""

project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Client: %s", err)
}
billingProject = project

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}

res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("IntegrationsClient %q", d.Id()))
}

res, err = resourceIntegrationsClientDecoder(d, meta, res)
if err != nil {
return err
}

if res == nil {
// Decoding the object has resulted in it being gone. It may be marked deleted
log.Printf("[DEBUG] Removing IntegrationsClient because it no longer exists.")
d.SetId("")
return nil
}

if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading Client: %s", err)
}

return nil
}

func resourceIntegrationsClientDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[WARNING] Integrations Client resources"+
" cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+
" state, but will still be present on Google Cloud.", d.Id())
d.SetId("")

return nil
}

func resourceIntegrationsClientImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*transport_tpg.Config)
if err := tpgresource.ParseImportId([]string{
"^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/clients$",
"^(?P<project>[^/]+)/(?P<location>[^/]+)$",
"^(?P<location>[^/]+)$",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/clients")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
}

func resourceIntegrationsClientDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Since Client resource doesnt have any properties,
// Adding this decoder as placeholder else the linter will
// complain that the returned `res` is never used afterwards.
return res, nil
}
Loading
Loading