-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…13080) Fixes #12520 Signed-off-by: Modular Magician <magic-modules@google.com> Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
85eb4f6
commit 7da3ffc
Showing
5 changed files
with
609 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
google_eventarc_google_channel_config | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** 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" | ||
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc" | ||
) | ||
|
||
func resourceEventarcGoogleChannelConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceEventarcGoogleChannelConfigCreate, | ||
Read: resourceEventarcGoogleChannelConfigRead, | ||
Update: resourceEventarcGoogleChannelConfigUpdate, | ||
Delete: resourceEventarcGoogleChannelConfigDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: resourceEventarcGoogleChannelConfigImport, | ||
}, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(20 * time.Minute), | ||
Update: schema.DefaultTimeout(20 * time.Minute), | ||
Delete: schema.DefaultTimeout(20 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"location": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "The location for the resource", | ||
}, | ||
|
||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Required. The resource name of the config. Must be in the format of, `projects/{project}/locations/{location}/googleChannelConfig`.", | ||
}, | ||
|
||
"crypto_key_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DiffSuppressFunc: compareSelfLinkOrResourceName, | ||
Description: "Optional. Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt their event data. It must match the pattern `projects/*/locations/*/keyRings/*/cryptoKeys/*`.", | ||
}, | ||
|
||
"project": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: compareSelfLinkOrResourceName, | ||
Description: "The project for the resource", | ||
}, | ||
|
||
"update_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Output only. The last-modified time.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceEventarcGoogleChannelConfigCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := &eventarc.GoogleChannelConfig{ | ||
Location: dcl.String(d.Get("location").(string)), | ||
Name: dcl.String(d.Get("name").(string)), | ||
CryptoKeyName: dcl.String(d.Get("crypto_key_name").(string)), | ||
Project: dcl.String(project), | ||
} | ||
|
||
id, err := obj.ID() | ||
if err != nil { | ||
return fmt.Errorf("error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
directive := UpdateDirective | ||
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 := NewDCLEventarcClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutCreate)) | ||
if bp, err := replaceVars(d, config, client.Config.BasePath); err != nil { | ||
d.SetId("") | ||
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) | ||
} else { | ||
client.Config.BasePath = bp | ||
} | ||
res, err := client.ApplyGoogleChannelConfig(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 creating GoogleChannelConfig: %s", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Finished creating GoogleChannelConfig %q: %#v", d.Id(), res) | ||
|
||
return resourceEventarcGoogleChannelConfigRead(d, meta) | ||
} | ||
|
||
func resourceEventarcGoogleChannelConfigRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := &eventarc.GoogleChannelConfig{ | ||
Location: dcl.String(d.Get("location").(string)), | ||
Name: dcl.String(d.Get("name").(string)), | ||
CryptoKeyName: dcl.String(d.Get("crypto_key_name").(string)), | ||
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 := NewDCLEventarcClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutRead)) | ||
if bp, err := replaceVars(d, config, client.Config.BasePath); err != nil { | ||
d.SetId("") | ||
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) | ||
} else { | ||
client.Config.BasePath = bp | ||
} | ||
res, err := client.GetGoogleChannelConfig(context.Background(), obj) | ||
if err != nil { | ||
resourceName := fmt.Sprintf("EventarcGoogleChannelConfig %q", d.Id()) | ||
return handleNotFoundDCLError(err, d, resourceName) | ||
} | ||
|
||
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("crypto_key_name", res.CryptoKeyName); err != nil { | ||
return fmt.Errorf("error setting crypto_key_name 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("update_time", res.UpdateTime); err != nil { | ||
return fmt.Errorf("error setting update_time in state: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
func resourceEventarcGoogleChannelConfigUpdate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := &eventarc.GoogleChannelConfig{ | ||
Location: dcl.String(d.Get("location").(string)), | ||
Name: dcl.String(d.Get("name").(string)), | ||
CryptoKeyName: dcl.String(d.Get("crypto_key_name").(string)), | ||
Project: dcl.String(project), | ||
} | ||
directive := UpdateDirective | ||
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 := NewDCLEventarcClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutUpdate)) | ||
if bp, err := replaceVars(d, config, client.Config.BasePath); err != nil { | ||
d.SetId("") | ||
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) | ||
} else { | ||
client.Config.BasePath = bp | ||
} | ||
res, err := client.ApplyGoogleChannelConfig(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 GoogleChannelConfig: %s", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Finished creating GoogleChannelConfig %q: %#v", d.Id(), res) | ||
|
||
return resourceEventarcGoogleChannelConfigRead(d, meta) | ||
} | ||
|
||
func resourceEventarcGoogleChannelConfigDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := &eventarc.GoogleChannelConfig{ | ||
Location: dcl.String(d.Get("location").(string)), | ||
Name: dcl.String(d.Get("name").(string)), | ||
CryptoKeyName: dcl.String(d.Get("crypto_key_name").(string)), | ||
Project: dcl.String(project), | ||
} | ||
|
||
log.Printf("[DEBUG] Deleting GoogleChannelConfig %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 := NewDCLEventarcClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutDelete)) | ||
if bp, err := replaceVars(d, config, client.Config.BasePath); err != nil { | ||
d.SetId("") | ||
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) | ||
} else { | ||
client.Config.BasePath = bp | ||
} | ||
if err := client.DeleteGoogleChannelConfig(context.Background(), obj); err != nil { | ||
return fmt.Errorf("Error deleting GoogleChannelConfig: %s", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Finished deleting GoogleChannelConfig %q", d.Id()) | ||
return nil | ||
} | ||
|
||
func resourceEventarcGoogleChannelConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
config := meta.(*Config) | ||
|
||
if err := parseImportId([]string{ | ||
"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/googleChannelConfig", | ||
"(?P<project>[^/]+)/(?P<location>[^/]+)", | ||
"(?P<location>[^/]+)", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := replaceVarsForId(d, config, "projects/{{project}}/locations/{{location}}/googleChannelConfig") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} |
Oops, something went wrong.