blob: 6ef1fe58c6ce55e54e269fa18f7d2fe8e1299c45 [file] [log] [blame]
// 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 clouddeploy
import (
"fmt"
"log"
"net/http"
"reflect"
"strings"
"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 ResourceClouddeployAutomation() *schema.Resource {
return &schema.Resource{
Create: resourceClouddeployAutomationCreate,
Read: resourceClouddeployAutomationRead,
Update: resourceClouddeployAutomationUpdate,
Delete: resourceClouddeployAutomationDelete,
Importer: &schema.ResourceImporter{
State: resourceClouddeployAutomationImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},
CustomizeDiff: customdiff.All(
tpgresource.SetAnnotationsDiff,
tpgresource.SetLabelsDiff,
tpgresource.DefaultProviderProject,
),
Schema: map[string]*schema.Schema{
"delivery_pipeline": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The delivery_pipeline for the resource`,
},
"location": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The location for the resource`,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Name of the 'Automation'.`,
},
"rules": {
Type: schema.TypeList,
Required: true,
Description: `Required. List of Automation rules associated with the Automation resource. Must have at least one rule and limited to 250 rules per Delivery Pipeline. Note: the order of the rules here is not the same as the order of execution.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"advance_rollout_rule": {
Type: schema.TypeList,
Optional: true,
Description: `Optional. The 'AdvanceRolloutRule' will automatically advance a successful Rollout.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
Description: `Required. ID of the rule. This id must be unique in the 'Automation' resource to which this rule belongs. The format is 'a-z{0,62}'.`,
},
"source_phases": {
Type: schema.TypeList,
Optional: true,
Description: `Optional. Proceeds only after phase name matched any one in the list. This value must consist of lower-case letters, numbers, and hyphens, start with a letter and end with a letter or a number, and have a max length of 63 characters. In other words, it must match the following regex: '^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$'.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"wait": {
Type: schema.TypeString,
Optional: true,
Description: `Optional. How long to wait after a rollout is finished.`,
},
},
},
},
"promote_release_rule": {
Type: schema.TypeList,
Optional: true,
Description: `Optional. 'PromoteReleaseRule' will automatically promote a release from the current target to a specified target.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
Description: `Required. ID of the rule. This id must be unique in the 'Automation' resource to which this rule belongs. The format is 'a-z{0,62}'.`,
},
"destination_phase": {
Type: schema.TypeString,
Optional: true,
Description: `Optional. The starting phase of the rollout created by this operation. Default to the first phase.`,
},
"destination_target_id": {
Type: schema.TypeString,
Optional: true,
Description: `Optional. The ID of the stage in the pipeline to which this 'Release' is deploying. If unspecified, default it to the next stage in the promotion flow. The value of this field could be one of the following: * The last segment of a target name. It only needs the ID to determine if the target is one of the stages in the promotion sequence defined in the pipeline. * "@next", the next target in the promotion sequence.`,
},
"wait": {
Type: schema.TypeString,
Optional: true,
Description: `Optional. How long the release need to be paused until being promoted to the next target.`,
},
},
},
},
},
},
},
"selector": {
Type: schema.TypeList,
Required: true,
Description: `Required. Selected resources to which the automation will be applied.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"targets": {
Type: schema.TypeList,
Required: true,
Description: `Contains attributes about a target.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
Description: `ID of the 'Target'. The value of this field could be one of the following: * The last segment of a target name. It only needs the ID to determine which target is being referred to * "*", all targets in a location.`,
},
"labels": {
Type: schema.TypeMap,
Computed: true,
Optional: true,
Description: `Target labels.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
"service_account": {
Type: schema.TypeString,
Required: true,
Description: `Required. Email address of the user-managed IAM service account that creates Cloud Deploy release and rollout resources.`,
},
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `Optional. User annotations. These attributes can only be set and used by the user, and not by Cloud Deploy. Annotations must meet the following constraints: * Annotations are key/value pairs. * Valid annotation keys have two segments: an optional prefix and name, separated by a slash ('/'). * The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ('[a-z0-9A-Z]') with dashes ('-'), underscores ('_'), dots ('.'), and alphanumerics between. * The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots('.'), not longer than 253 characters in total, followed by a slash ('/'). See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set for more details.
**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration.
Please refer to the field 'effective_annotations' for all of the annotations present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `Optional. Description of the 'Automation'. Max length is 255 characters.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Optional. Labels are attributes that can be set and used by both the user and by Cloud Deploy. Labels must meet the following constraints: * Keys and values can contain only lowercase letters, numeric characters, underscores, and dashes. * All characters must use UTF-8 encoding, and international characters are allowed. * Keys must start with a lowercase letter or international character. * Each resource is limited to a maximum of 64 labels. Both keys and values are additionally constrained to be <= 63 characters.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"suspended": {
Type: schema.TypeBool,
Optional: true,
Description: `Optional. When Suspended, automation is deactivated from execution.`,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: `Output only. Time at which the automation was created.`,
},
"effective_annotations": {
Type: schema.TypeMap,
Computed: true,
Description: `All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"effective_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"etag": {
Type: schema.TypeString,
Computed: true,
Description: `Optional. The weak etag of the 'Automation' resource. This checksum is computed by the server based on the value of other fields, and may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.`,
},
"terraform_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `The combination of labels configured directly on the resource
and default labels configured on the provider.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"uid": {
Type: schema.TypeString,
Computed: true,
Description: `Output only. Unique identifier of the 'Automation'.`,
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: `Output only. Time at which the automation was updated.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
UseJSONNumber: true,
}
}
func resourceClouddeployAutomationCreate(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{})
descriptionProp, err := expandClouddeployAutomationDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
suspendedProp, err := expandClouddeployAutomationSuspended(d.Get("suspended"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("suspended"); ok || !reflect.DeepEqual(v, suspendedProp) {
obj["suspended"] = suspendedProp
}
serviceAccountProp, err := expandClouddeployAutomationServiceAccount(d.Get("service_account"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("service_account"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceAccountProp)) && (ok || !reflect.DeepEqual(v, serviceAccountProp)) {
obj["serviceAccount"] = serviceAccountProp
}
selectorProp, err := expandClouddeployAutomationSelector(d.Get("selector"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("selector"); !tpgresource.IsEmptyValue(reflect.ValueOf(selectorProp)) && (ok || !reflect.DeepEqual(v, selectorProp)) {
obj["selector"] = selectorProp
}
rulesProp, err := expandClouddeployAutomationRules(d.Get("rules"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("rules"); !tpgresource.IsEmptyValue(reflect.ValueOf(rulesProp)) && (ok || !reflect.DeepEqual(v, rulesProp)) {
obj["rules"] = rulesProp
}
annotationsProp, err := expandClouddeployAutomationEffectiveAnnotations(d.Get("effective_annotations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
obj["annotations"] = annotationsProp
}
labelsProp, err := expandClouddeployAutomationEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
url, err := tpgresource.ReplaceVars(d, config, "{{ClouddeployBasePath}}projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations?automationId={{name}}")
if err != nil {
return err
}
log.Printf("[DEBUG] Creating new Automation: %#v", obj)
billingProject := ""
project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Automation: %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
}
headers := make(http.Header)
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),
Headers: headers,
})
if err != nil {
return fmt.Errorf("Error creating Automation: %s", err)
}
// Store the ID now
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations/{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
err = ClouddeployOperationWaitTime(
config, res, project, "Creating Automation", userAgent,
d.Timeout(schema.TimeoutCreate))
if err != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error waiting to create Automation: %s", err)
}
log.Printf("[DEBUG] Finished creating Automation %q: %#v", d.Id(), res)
return resourceClouddeployAutomationRead(d, meta)
}
func resourceClouddeployAutomationRead(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, "{{ClouddeployBasePath}}projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations/{{name}}")
if err != nil {
return err
}
billingProject := ""
project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Automation: %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
}
headers := make(http.Header)
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Headers: headers,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("ClouddeployAutomation %q", d.Id()))
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("uid", flattenClouddeployAutomationUid(res["uid"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("description", flattenClouddeployAutomationDescription(res["description"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("create_time", flattenClouddeployAutomationCreateTime(res["createTime"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("update_time", flattenClouddeployAutomationUpdateTime(res["updateTime"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("annotations", flattenClouddeployAutomationAnnotations(res["annotations"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("labels", flattenClouddeployAutomationLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("etag", flattenClouddeployAutomationEtag(res["etag"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("suspended", flattenClouddeployAutomationSuspended(res["suspended"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("service_account", flattenClouddeployAutomationServiceAccount(res["serviceAccount"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("selector", flattenClouddeployAutomationSelector(res["selector"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("rules", flattenClouddeployAutomationRules(res["rules"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("effective_annotations", flattenClouddeployAutomationEffectiveAnnotations(res["annotations"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("terraform_labels", flattenClouddeployAutomationTerraformLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
if err := d.Set("effective_labels", flattenClouddeployAutomationEffectiveLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Automation: %s", err)
}
return nil
}
func resourceClouddeployAutomationUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
billingProject := ""
project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Automation: %s", err)
}
billingProject = project
obj := make(map[string]interface{})
descriptionProp, err := expandClouddeployAutomationDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
suspendedProp, err := expandClouddeployAutomationSuspended(d.Get("suspended"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("suspended"); ok || !reflect.DeepEqual(v, suspendedProp) {
obj["suspended"] = suspendedProp
}
serviceAccountProp, err := expandClouddeployAutomationServiceAccount(d.Get("service_account"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("service_account"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, serviceAccountProp)) {
obj["serviceAccount"] = serviceAccountProp
}
selectorProp, err := expandClouddeployAutomationSelector(d.Get("selector"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("selector"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, selectorProp)) {
obj["selector"] = selectorProp
}
rulesProp, err := expandClouddeployAutomationRules(d.Get("rules"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("rules"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, rulesProp)) {
obj["rules"] = rulesProp
}
annotationsProp, err := expandClouddeployAutomationEffectiveAnnotations(d.Get("effective_annotations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
obj["annotations"] = annotationsProp
}
labelsProp, err := expandClouddeployAutomationEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
url, err := tpgresource.ReplaceVars(d, config, "{{ClouddeployBasePath}}projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations/{{name}}")
if err != nil {
return err
}
log.Printf("[DEBUG] Updating Automation %q: %#v", d.Id(), obj)
headers := make(http.Header)
updateMask := []string{}
if d.HasChange("description") {
updateMask = append(updateMask, "description")
}
if d.HasChange("suspended") {
updateMask = append(updateMask, "suspended")
}
if d.HasChange("service_account") {
updateMask = append(updateMask, "serviceAccount")
}
if d.HasChange("selector") {
updateMask = append(updateMask, "selector")
}
if d.HasChange("rules") {
updateMask = append(updateMask, "rules")
}
if d.HasChange("effective_annotations") {
updateMask = append(updateMask, "annotations")
}
if d.HasChange("effective_labels") {
updateMask = append(updateMask, "labels")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
// if updateMask is empty we are not updating anything so skip the post
if len(updateMask) > 0 {
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PATCH",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
Headers: headers,
})
if err != nil {
return fmt.Errorf("Error updating Automation %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating Automation %q: %#v", d.Id(), res)
}
err = ClouddeployOperationWaitTime(
config, res, project, "Updating Automation", userAgent,
d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
}
return resourceClouddeployAutomationRead(d, meta)
}
func resourceClouddeployAutomationDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
billingProject := ""
project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Automation: %s", err)
}
billingProject = project
url, err := tpgresource.ReplaceVars(d, config, "{{ClouddeployBasePath}}projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations/{{name}}")
if err != nil {
return err
}
var obj map[string]interface{}
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
headers := make(http.Header)
log.Printf("[DEBUG] Deleting Automation %q", d.Id())
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "DELETE",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutDelete),
Headers: headers,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, "Automation")
}
err = ClouddeployOperationWaitTime(
config, res, project, "Deleting Automation", userAgent,
d.Timeout(schema.TimeoutDelete))
if err != nil {
return err
}
log.Printf("[DEBUG] Finished deleting Automation %q: %#v", d.Id(), res)
return nil
}
func resourceClouddeployAutomationImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*transport_tpg.Config)
if err := tpgresource.ParseImportId([]string{
"^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/deliveryPipelines/(?P<delivery_pipeline>[^/]+)/automations/(?P<name>[^/]+)$",
"^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<delivery_pipeline>[^/]+)/(?P<name>[^/]+)$",
"^(?P<location>[^/]+)/(?P<delivery_pipeline>[^/]+)/(?P<name>[^/]+)$",
}, d, config); err != nil {
return nil, err
}
// Replace import id for the resource id
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return []*schema.ResourceData{d}, nil
}
func flattenClouddeployAutomationUid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
transformed := make(map[string]interface{})
if l, ok := d.GetOkExists("annotations"); ok {
for k := range l.(map[string]interface{}) {
transformed[k] = v.(map[string]interface{})[k]
}
}
return transformed
}
func flattenClouddeployAutomationLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
transformed := make(map[string]interface{})
if l, ok := d.GetOkExists("labels"); ok {
for k := range l.(map[string]interface{}) {
transformed[k] = v.(map[string]interface{})[k]
}
}
return transformed
}
func flattenClouddeployAutomationEtag(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationSuspended(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationSelector(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["targets"] =
flattenClouddeployAutomationSelectorTargets(original["targets"], d, config)
return []interface{}{transformed}
}
func flattenClouddeployAutomationSelectorTargets(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
"id": flattenClouddeployAutomationSelectorTargetsId(original["id"], d, config),
"labels": flattenClouddeployAutomationSelectorTargetsLabels(original["labels"], d, config),
})
}
return transformed
}
func flattenClouddeployAutomationSelectorTargetsId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationSelectorTargetsLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRules(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
"promote_release_rule": flattenClouddeployAutomationRulesPromoteReleaseRule(original["promoteReleaseRule"], d, config),
"advance_rollout_rule": flattenClouddeployAutomationRulesAdvanceRolloutRule(original["advanceRolloutRule"], d, config),
})
}
return transformed
}
func flattenClouddeployAutomationRulesPromoteReleaseRule(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["id"] =
flattenClouddeployAutomationRulesPromoteReleaseRuleId(original["id"], d, config)
transformed["wait"] =
flattenClouddeployAutomationRulesPromoteReleaseRuleWait(original["wait"], d, config)
transformed["destination_target_id"] =
flattenClouddeployAutomationRulesPromoteReleaseRuleDestinationTargetId(original["destinationTargetId"], d, config)
transformed["destination_phase"] =
flattenClouddeployAutomationRulesPromoteReleaseRuleDestinationPhase(original["destinationPhase"], d, config)
return []interface{}{transformed}
}
func flattenClouddeployAutomationRulesPromoteReleaseRuleId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRulesPromoteReleaseRuleWait(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRulesPromoteReleaseRuleDestinationTargetId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRulesPromoteReleaseRuleDestinationPhase(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRulesAdvanceRolloutRule(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["id"] =
flattenClouddeployAutomationRulesAdvanceRolloutRuleId(original["id"], d, config)
transformed["wait"] =
flattenClouddeployAutomationRulesAdvanceRolloutRuleWait(original["wait"], d, config)
transformed["source_phases"] =
flattenClouddeployAutomationRulesAdvanceRolloutRuleSourcePhases(original["sourcePhases"], d, config)
return []interface{}{transformed}
}
func flattenClouddeployAutomationRulesAdvanceRolloutRuleId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRulesAdvanceRolloutRuleWait(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationRulesAdvanceRolloutRuleSourcePhases(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationEffectiveAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func flattenClouddeployAutomationTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
transformed := make(map[string]interface{})
if l, ok := d.GetOkExists("terraform_labels"); ok {
for k := range l.(map[string]interface{}) {
transformed[k] = v.(map[string]interface{})[k]
}
}
return transformed
}
func flattenClouddeployAutomationEffectiveLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
func expandClouddeployAutomationDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationSuspended(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationServiceAccount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationSelector(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})
transformedTargets, err := expandClouddeployAutomationSelectorTargets(original["targets"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTargets); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["targets"] = transformedTargets
}
return transformed, nil
}
func expandClouddeployAutomationSelectorTargets(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
if raw == nil {
continue
}
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})
transformedId, err := expandClouddeployAutomationSelectorTargetsId(original["id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["id"] = transformedId
}
transformedLabels, err := expandClouddeployAutomationSelectorTargetsLabels(original["labels"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedLabels); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["labels"] = transformedLabels
}
req = append(req, transformed)
}
return req, nil
}
func expandClouddeployAutomationSelectorTargetsId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationSelectorTargetsLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}
func expandClouddeployAutomationRules(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
if raw == nil {
continue
}
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})
transformedPromoteReleaseRule, err := expandClouddeployAutomationRulesPromoteReleaseRule(original["promote_release_rule"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPromoteReleaseRule); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["promoteReleaseRule"] = transformedPromoteReleaseRule
}
transformedAdvanceRolloutRule, err := expandClouddeployAutomationRulesAdvanceRolloutRule(original["advance_rollout_rule"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAdvanceRolloutRule); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["advanceRolloutRule"] = transformedAdvanceRolloutRule
}
req = append(req, transformed)
}
return req, nil
}
func expandClouddeployAutomationRulesPromoteReleaseRule(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})
transformedId, err := expandClouddeployAutomationRulesPromoteReleaseRuleId(original["id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["id"] = transformedId
}
transformedWait, err := expandClouddeployAutomationRulesPromoteReleaseRuleWait(original["wait"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedWait); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["wait"] = transformedWait
}
transformedDestinationTargetId, err := expandClouddeployAutomationRulesPromoteReleaseRuleDestinationTargetId(original["destination_target_id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDestinationTargetId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["destinationTargetId"] = transformedDestinationTargetId
}
transformedDestinationPhase, err := expandClouddeployAutomationRulesPromoteReleaseRuleDestinationPhase(original["destination_phase"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDestinationPhase); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["destinationPhase"] = transformedDestinationPhase
}
return transformed, nil
}
func expandClouddeployAutomationRulesPromoteReleaseRuleId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationRulesPromoteReleaseRuleWait(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationRulesPromoteReleaseRuleDestinationTargetId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationRulesPromoteReleaseRuleDestinationPhase(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationRulesAdvanceRolloutRule(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})
transformedId, err := expandClouddeployAutomationRulesAdvanceRolloutRuleId(original["id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["id"] = transformedId
}
transformedWait, err := expandClouddeployAutomationRulesAdvanceRolloutRuleWait(original["wait"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedWait); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["wait"] = transformedWait
}
transformedSourcePhases, err := expandClouddeployAutomationRulesAdvanceRolloutRuleSourcePhases(original["source_phases"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSourcePhases); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["sourcePhases"] = transformedSourcePhases
}
return transformed, nil
}
func expandClouddeployAutomationRulesAdvanceRolloutRuleId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationRulesAdvanceRolloutRuleWait(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationRulesAdvanceRolloutRuleSourcePhases(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
func expandClouddeployAutomationEffectiveAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}
func expandClouddeployAutomationEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}