Skip to content

Commit e613a66

Browse files
Backfill terraform_labels with state upgrader for the immutable MMv1 resources (#9438) (#16518)
[upstream:61ca630b03604b8cab95d14849022aebf88971e5] Signed-off-by: Modular Magician <[email protected]>
1 parent 75085b2 commit e613a66

7 files changed

+1459
-0
lines changed

.changelog/9438.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
provider: backfilled `terraform_labels` for some immutable resources, so resource recreation won't happen during provider upgrade from 4.X to 5.7
3+
```

google/services/beyondcorp/resource_beyondcorp_app_gateway.go

+117
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package beyondcorp
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"log"
2324
"reflect"
@@ -46,6 +47,15 @@ func ResourceBeyondcorpAppGateway() *schema.Resource {
4647
Delete: schema.DefaultTimeout(20 * time.Minute),
4748
},
4849

50+
SchemaVersion: 1,
51+
52+
StateUpgraders: []schema.StateUpgrader{
53+
{
54+
Type: resourceBeyondcorpAppGatewayResourceV0().CoreConfigSchema().ImpliedType(),
55+
Upgrade: ResourceBeyondcorpAppGatewayUpgradeV0,
56+
Version: 0,
57+
},
58+
},
4959
CustomizeDiff: customdiff.All(
5060
tpgresource.SetLabelsDiff,
5161
tpgresource.DefaultProviderProject,
@@ -506,3 +516,110 @@ func expandBeyondcorpAppGatewayEffectiveLabels(v interface{}, d tpgresource.Terr
506516
}
507517
return m, nil
508518
}
519+
520+
func resourceBeyondcorpAppGatewayResourceV0() *schema.Resource {
521+
return &schema.Resource{
522+
Schema: map[string]*schema.Schema{
523+
"name": {
524+
Type: schema.TypeString,
525+
Required: true,
526+
ForceNew: true,
527+
Description: `ID of the AppGateway.`,
528+
},
529+
"display_name": {
530+
Type: schema.TypeString,
531+
Optional: true,
532+
ForceNew: true,
533+
Description: `An arbitrary user-provided name for the AppGateway.`,
534+
},
535+
"host_type": {
536+
Type: schema.TypeString,
537+
Optional: true,
538+
ForceNew: true,
539+
ValidateFunc: verify.ValidateEnum([]string{"HOST_TYPE_UNSPECIFIED", "GCP_REGIONAL_MIG", ""}),
540+
Description: `The type of hosting used by the AppGateway. Default value: "HOST_TYPE_UNSPECIFIED" Possible values: ["HOST_TYPE_UNSPECIFIED", "GCP_REGIONAL_MIG"]`,
541+
Default: "HOST_TYPE_UNSPECIFIED",
542+
},
543+
"labels": {
544+
Type: schema.TypeMap,
545+
Optional: true,
546+
ForceNew: true,
547+
Description: `Resource labels to represent user provided metadata.
548+
549+
550+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
551+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
552+
Elem: &schema.Schema{Type: schema.TypeString},
553+
},
554+
"region": {
555+
Type: schema.TypeString,
556+
Optional: true,
557+
ForceNew: true,
558+
Description: `The region of the AppGateway.`,
559+
},
560+
"type": {
561+
Type: schema.TypeString,
562+
Optional: true,
563+
ForceNew: true,
564+
ValidateFunc: verify.ValidateEnum([]string{"TYPE_UNSPECIFIED", "TCP_PROXY", ""}),
565+
Description: `The type of network connectivity used by the AppGateway. Default value: "TYPE_UNSPECIFIED" Possible values: ["TYPE_UNSPECIFIED", "TCP_PROXY"]`,
566+
Default: "TYPE_UNSPECIFIED",
567+
},
568+
"allocated_connections": {
569+
Type: schema.TypeList,
570+
Computed: true,
571+
Description: `A list of connections allocated for the Gateway.`,
572+
Elem: &schema.Resource{
573+
Schema: map[string]*schema.Schema{
574+
"ingress_port": {
575+
Type: schema.TypeInt,
576+
Optional: true,
577+
Description: `The ingress port of an allocated connection.`,
578+
},
579+
"psc_uri": {
580+
Type: schema.TypeString,
581+
Optional: true,
582+
Description: `The PSC uri of an allocated connection.`,
583+
},
584+
},
585+
},
586+
},
587+
"effective_labels": {
588+
Type: schema.TypeMap,
589+
Computed: true,
590+
ForceNew: true,
591+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
592+
Elem: &schema.Schema{Type: schema.TypeString},
593+
},
594+
"state": {
595+
Type: schema.TypeString,
596+
Computed: true,
597+
Description: `Represents the different states of a AppGateway.`,
598+
},
599+
"terraform_labels": {
600+
Type: schema.TypeMap,
601+
Computed: true,
602+
ForceNew: true,
603+
Description: `The combination of labels configured directly on the resource
604+
and default labels configured on the provider.`,
605+
Elem: &schema.Schema{Type: schema.TypeString},
606+
},
607+
"uri": {
608+
Type: schema.TypeString,
609+
Computed: true,
610+
Description: `Server-defined URI for this resource.`,
611+
},
612+
"project": {
613+
Type: schema.TypeString,
614+
Optional: true,
615+
Computed: true,
616+
ForceNew: true,
617+
},
618+
},
619+
UseJSONNumber: true,
620+
}
621+
}
622+
623+
func ResourceBeyondcorpAppGatewayUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
624+
return tpgresource.TerraformLabelsStateUpgrade(rawState)
625+
}

0 commit comments

Comments
 (0)