Skip to content

Commit

Permalink
Backfill terraform_labels with state upgrader for the immutable MMv1 …
Browse files Browse the repository at this point in the history
…resources (#9438) (#16518)

[upstream:61ca630b03604b8cab95d14849022aebf88971e5]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Nov 13, 2023
1 parent 75085b2 commit e613a66
Show file tree
Hide file tree
Showing 7 changed files with 1,459 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/9438.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
provider: backfilled `terraform_labels` for some immutable resources, so resource recreation won't happen during provider upgrade from 4.X to 5.7
```
117 changes: 117 additions & 0 deletions google/services/beyondcorp/resource_beyondcorp_app_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package beyondcorp

import (
"context"
"fmt"
"log"
"reflect"
Expand Down Expand Up @@ -46,6 +47,15 @@ func ResourceBeyondcorpAppGateway() *schema.Resource {
Delete: schema.DefaultTimeout(20 * time.Minute),
},

SchemaVersion: 1,

StateUpgraders: []schema.StateUpgrader{
{
Type: resourceBeyondcorpAppGatewayResourceV0().CoreConfigSchema().ImpliedType(),
Upgrade: ResourceBeyondcorpAppGatewayUpgradeV0,
Version: 0,
},
},
CustomizeDiff: customdiff.All(
tpgresource.SetLabelsDiff,
tpgresource.DefaultProviderProject,
Expand Down Expand Up @@ -506,3 +516,110 @@ func expandBeyondcorpAppGatewayEffectiveLabels(v interface{}, d tpgresource.Terr
}
return m, nil
}

func resourceBeyondcorpAppGatewayResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `ID of the AppGateway.`,
},
"display_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `An arbitrary user-provided name for the AppGateway.`,
},
"host_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"HOST_TYPE_UNSPECIFIED", "GCP_REGIONAL_MIG", ""}),
Description: `The type of hosting used by the AppGateway. Default value: "HOST_TYPE_UNSPECIFIED" Possible values: ["HOST_TYPE_UNSPECIFIED", "GCP_REGIONAL_MIG"]`,
Default: "HOST_TYPE_UNSPECIFIED",
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Resource labels to represent user provided metadata.
**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},
},
"region": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The region of the AppGateway.`,
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"TYPE_UNSPECIFIED", "TCP_PROXY", ""}),
Description: `The type of network connectivity used by the AppGateway. Default value: "TYPE_UNSPECIFIED" Possible values: ["TYPE_UNSPECIFIED", "TCP_PROXY"]`,
Default: "TYPE_UNSPECIFIED",
},
"allocated_connections": {
Type: schema.TypeList,
Computed: true,
Description: `A list of connections allocated for the Gateway.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ingress_port": {
Type: schema.TypeInt,
Optional: true,
Description: `The ingress port of an allocated connection.`,
},
"psc_uri": {
Type: schema.TypeString,
Optional: true,
Description: `The PSC uri of an allocated connection.`,
},
},
},
},
"effective_labels": {
Type: schema.TypeMap,
Computed: true,
ForceNew: 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},
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: `Represents the different states of a AppGateway.`,
},
"terraform_labels": {
Type: schema.TypeMap,
Computed: true,
ForceNew: true,
Description: `The combination of labels configured directly on the resource
and default labels configured on the provider.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"uri": {
Type: schema.TypeString,
Computed: true,
Description: `Server-defined URI for this resource.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
UseJSONNumber: true,
}
}

func ResourceBeyondcorpAppGatewayUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
return tpgresource.TerraformLabelsStateUpgrade(rawState)
}
Loading

0 comments on commit e613a66

Please sign in to comment.