Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into dataset-acl-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
obada-ab authored Dec 13, 2024
2 parents dbdc91f + 3b3cb68 commit a7af1b3
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 39 deletions.
1 change: 1 addition & 0 deletions .ci/magician/cmd/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ExecRunner interface {
RemoveAll(path string) error
PushDir(path string) error
PopDir() error
ReadFile(name string) (string, error)
WriteFile(name, data string) error
AppendFile(name, data string) error // Not used (yet).
Run(name string, args []string, env map[string]string) (string, error)
Expand Down
4 changes: 2 additions & 2 deletions .ci/magician/cmd/test_eap_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func execTestEAPVCR(changeNumber, genPath, kokoroArtifactsDir, modifiedFilePath
return fmt.Errorf("error changing to gen path: %w", err)
}

changedFiles, err := rnr.Run("git", []string{"diff", "--name-only"}, nil)
changedFiles, err := rnr.ReadFile("diff.log")
if err != nil {
return fmt.Errorf("error diffing gen path: %w", err)
return fmt.Errorf("error reading diff log: %w", err)
}

services, runFullVCR := modifiedPackages(strings.Split(changedFiles, "\n"), provider.Private)
Expand Down
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

4 changes: 2 additions & 2 deletions docs/content/best-practices/common-resource-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Singletons are resources – often config or settings objects – that can only

Implementing resources like this may require some or all of the following:

1. If there _isn't_ a create endpoint, set the [create_url]({{< ref "/develop/resource-reference/#create_url" >}}) to point to the update endpoint.
1. If there _isn't_ a create endpoint, set the [create_url]({{< ref "/reference/resource-reference/#create_url" >}}) to point to the update endpoint.
1. If there _is_ a create endpoint, add [pre-create custom code]({{< ref "/develop/custom-code/#pre_post_injection" >}}) that implements "acquire-on-create" logic. The custom code should check whether the resource already exists with a read request, and if it does, run the update logic and return early. For example, see [mmv1/templates/terraform/pre_create/firebasehosting_site.go.tmpl](https://github.com/GoogleCloudPlatform/magic-modules/blob/dc4d9755cb9288177e0996c1c3b3fa9738ebdf89/mmv1/templates/terraform/pre_create/firebasehosting_site.go.tmpl).
* Note: The main disadvantage of "acquire-on-create" logic is that users will not be presented with a diff between the resource's old and new states – because from the terraform perspective, the resource is only being created. Please upvote https://github.com/hashicorp/terraform/issues/19017 to request better support for this workflow.
1. If there is no delete endpoint, set [`exclude_delete: true`]({{< ref "/develop/resource-reference/#create_url" >}}) at the top level of the resource.
1. If there is no delete endpoint, set [`exclude_delete: true`]({{< ref "/reference/resource-reference/#create_url" >}}) at the top level of the resource.
2 changes: 1 addition & 1 deletion docs/content/best-practices/deletion-behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ See [Client-side fields]({{< ref "/develop/client-side-fields" >}}) for informat

## Exclude deletion {#exclude_delete}

Some resources do not support deletion in the API and can only be removed from state. For these resources, the best practice is to set [`exclude_delete: true`]({{< ref "/develop/resource-reference#exclude_delete" >}}) on the resource.
Some resources do not support deletion in the API and can only be removed from state. For these resources, the best practice is to set [`exclude_delete: true`]({{< ref "/reference/resource-reference#exclude_delete" >}}) on the resource.
2 changes: 1 addition & 1 deletion docs/content/develop/add-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ For `key_name` and `key_description`, provide a domain-appropriate name and desc

2. Modify the field configuration according to the API documentation and behavior.

> **Note:** The templates in this section only include the most commonly-used fields. For a comprehensive reference, see [MMv1 field reference]({{<ref "/develop/field-reference" >}}). For information about modifying the values sent and received for a field, see [Modify the API request or response]({{<ref "/develop/custom-code#modify-the-api-request-or-response" >}}).
> **Note:** The templates in this section only include the most commonly-used fields. For a comprehensive reference, see [MMv1 field reference]({{<ref "/reference/field-reference" >}}). For information about modifying the values sent and received for a field, see [Modify the API request or response]({{<ref "/develop/custom-code#modify-the-api-request-or-response" >}}).
{{< /tab >}}
{{< tab "Handwritten" >}}
1. Add the field to the handwritten resource's schema.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/develop/add-iam-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ iam_policy:
# min_version: beta
```

2. Modify the template as needed to match the API resource's documented behavior. These are the most commonly-used fields. For a comprehensive reference, see [MMv1 resource reference: `iam_policy`]({{<ref "/develop/resource-reference#iam_policy" >}}).
2. Modify the template as needed to match the API resource's documented behavior. These are the most commonly-used fields. For a comprehensive reference, see [MMv1 resource reference: `iam_policy`]({{<ref "/reference/resource-reference#iam_policy" >}}).
3. Delete all remaining comments in the IAM configuration (including attribute descriptions) that were copied from the above template.
{{< /tab >}}
{{< tab "Handwritten" >}}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/develop/add-resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ For more information about types of resources and the generation process overall
3. Modify the template as needed to match the API resource's documented behavior.
4. Delete all remaining comments in the resource configuration (including attribute descriptions) that were copied from the above template.

> **Note:** The template includes the most commonly-used fields. For a comprehensive reference, see [MMv1 resource reference ↗]({{<ref "/develop/resource-reference" >}}).
> **Note:** The template includes the most commonly-used fields. For a comprehensive reference, see [MMv1 resource reference ↗]({{<ref "/reference/resource-reference" >}}).
{{< /tab >}}
{{< tab "Handwritten" >}}
> **Warning:** Handwritten resources are more difficult to develop and maintain. New handwritten resources will only be accepted if implementing the resource in MMv1 would require entirely overriding two or more CRUD methods.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/develop/custom-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Use `custom_code.constants` to inject top-level code in a resource file. This is

- Constants
- Regexes compiled at build time
- Functions, such as [diff suppress functions]({{<ref "/develop/field-reference#diff_suppress_func" >}}),
[validation functions]({{<ref "/develop/field-reference#validation" >}}),
- Functions, such as [diff suppress functions]({{<ref "/reference/field-reference#diff_suppress_func" >}}),
[validation functions]({{<ref "/reference/field-reference#validation" >}}),
CustomizeDiff functions, and so on.
- Methods

Expand Down
2 changes: 1 addition & 1 deletion docs/content/develop/diffs.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ See [SDKv2 Schema Behaviors - DiffSuppressFunc ↗](https://developer.hashicorp.

## API field that is never included in the response {#ignore_read}

This is common for fields that store credentials or similar information. Such fields should also be marked as [`sensitive`]({{< ref "/develop/field-reference#sensitive" >}}).
This is common for fields that store credentials or similar information. Such fields should also be marked as [`sensitive`]({{< ref "/reference/field-reference#sensitive" >}}).

In the flattener for the field, return the value of the field in the user's configuration.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
title: "MMv1 field reference"
weight: 120
weight: 20
aliases:
- /reference/field-reference
- /develop/field-reference
---

# MMv1 field reference
Expand Down Expand Up @@ -280,7 +281,7 @@ This property has two mutually exclusive child properties:
[`function: verify.ValidateRegexp(REGEX_STRING)`](https://github.com/hashicorp/terraform-provider-google-beta/blob/0ef51142a4dd1c1a4fc308c1eb09dce307ebe5f5/google-beta/verify/validation.go#L425).

`validation` is not supported for Array fields (including sets); however, individual
elements in the array can be validated using [`item_validation`]({{<ref "/develop/field-reference#item_validation" >}}).
elements in the array can be validated using [`item_validation`]({{<ref "/reference/field-reference#item_validation" >}}).

Example: Provider-specific function

Expand Down Expand Up @@ -331,7 +332,7 @@ stating the current allowed values in the String field's description. Do not
include UNSPECIFIED values in this list.

Enums will validate that the provided field is in the allowed list unless a
custom [`validation`]({{<ref "/develop/field-reference#validation" >}}) is provided.
custom [`validation`]({{<ref "/reference/field-reference#validation" >}}) is provided.

Example:

Expand Down Expand Up @@ -380,7 +381,7 @@ item_type:

### `item_validation`
Array only. Controls the [`ValidateFunc`](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#validatefunc)
used to validate individual items in the array. Behaves like [`validation`]({{<ref "/develop/field-reference#validation" >}}).
used to validate individual items in the array. Behaves like [`validation`]({{<ref "/reference/field-reference#validation" >}}).

For arrays of enums, this will override the default validation (that the provided value is one of the enum [`values`](#values)).
If you need additional validation on top of an enum, ensure that the supplied validation func also verifies the enum
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/make-commands.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "make commands"
weight: 10
weight: 30
---
# `make` commands reference

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
title: "MMv1 resource reference"
weight: 130
weight: 10
aliases:
- /reference/resource-reference
- /reference/iam-policy-reference
- /develop/resource-reference
---

# MMv1 resource reference
Expand Down Expand Up @@ -334,12 +335,12 @@ the behavior of a Terraform resource such as `deletion_protection`.

### `parameters`

Contains a list of [fields]({{< ref "/develop/field-reference" >}}). By convention,
Contains a list of [fields]({{< ref "/reference/field-reference" >}}). By convention,
these should be the fields that are part URL parameters such as `location` and `name`.

### `properties`

Contains a list of [fields]({{< ref "/develop/field-reference" >}}). By convention,
Contains a list of [fields]({{< ref "/reference/field-reference" >}}). By convention,
these should be fields that aren't part of the URL parameters.

Example:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/ruby-go-changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Ruby to Go Migration"
weight: 10
weight: 40
---
# What has changed in the MMv1 Go migration

Expand Down
4 changes: 2 additions & 2 deletions docs/content/test/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ An update test is a test that creates the target resource and then makes updates
## Add unit tests

A unit test verifies functionality that is not related to interactions with the API, such as
[diff suppress functions]({{<ref "/develop/field-reference#diff_suppress_func" >}}),
[validation functions]({{<ref "/develop/field-reference#validation" >}}),
[diff suppress functions]({{<ref "/reference/field-reference#diff_suppress_func" >}}),
[validation functions]({{<ref "/reference/field-reference#validation" >}}),
CustomizeDiff functions, and so on.

Unit tests should be added to the appropriate folder in [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) in the file called `resource_PRODUCT_RESOURCE_test.go`. (You may need to create this file if it does not already exist. Replace PRODUCT with the product name and RESOURCE with the resource name; it should match the name of the generated resource file.)
Expand Down
2 changes: 2 additions & 0 deletions mmv1/products/compute/HaVpnGateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ async:
resource_inside_response: false
collection_url_key: 'items'
custom_code:
schema_version: 1
state_upgraders: true
examples:
- name: 'ha_vpn_gateway_basic'
primary_resource_id: 'ha_gateway1'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
func resourceComputeHaVpnGatewayResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidateGCEName,
Description: `Name of the resource. Provided by the client when the resource is
created. The name must be 1-63 characters long, and comply with
RFC1035. Specifically, the name must be 1-63 characters long and
match the regular expression '[a-z]([-a-z0-9]*[a-z0-9])?' which means
the first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.`,
},
"network": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The network this VPN gateway is accepting traffic for.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `An optional description of this resource.`,
},
"gateway_ip_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"IPV4", "IPV6", ""}),
Description: `The IP family of the gateway IPs for the HA-VPN gateway interfaces. If not specified, IPV4 will be used. Default value: "IPV4" Possible values: ["IPV4", "IPV6"]`,
Default: "IPV4",
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The region this gateway should sit in.`,
},
"stack_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"IPV4_ONLY", "IPV4_IPV6", "IPV6_ONLY", ""}),
Description: `The stack type for this VPN gateway to identify the IP protocols that are enabled.
If not specified, IPV4_ONLY will be used. Default value: "IPV4_ONLY" Possible values: ["IPV4_ONLY", "IPV4_IPV6", "IPV6_ONLY"]`,
Default: "IPV4_ONLY",
},
"vpn_interfaces": {
Type: schema.TypeList,
Computed: true,
Optional: true,
ForceNew: true,
Description: `A list of interfaces on this VPN gateway.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `The numeric ID of this VPN gateway interface.`,
},
"interconnect_attachment": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `URL of the interconnect attachment resource. When the value
of this field is present, the VPN Gateway will be used for
IPsec-encrypted Cloud Interconnect; all Egress or Ingress
traffic for this VPN Gateway interface will go through the
specified interconnect attachment resource.

Not currently available publicly.`,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
Description: `The external IP address for this VPN gateway interface.`,
},
},
},
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"self_link": {
Type: schema.TypeString,
Computed: true,
},
},
UseJSONNumber: true,
}
}

func ResourceComputeHaVpnGatewayUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
log.Printf("[DEBUG] Attributes before migration: %#v", rawState)


// Check if "gateway_ip_version" already exists
if _, ok := rawState["gateway_ip_version"]; !ok {
// Add the missing attribute with the default value
rawState["gateway_ip_version"] = "IPV4"
} else {
log.Printf("[DEBUG] 'gateway_ip_version' already exists: %#v", rawState["gateway_ip_version"])
}

log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
return rawState, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ var handwrittenDatasources = map[string]*schema.Resource{
"google_apphub_discovered_service": apphub.DataSourceApphubDiscoveredService(),
{{- if ne $.TargetVersionName "ga" }}
"google_backup_dr_management_server": backupdr.DataSourceGoogleCloudBackupDRService(),
"google_backup_dr_backup": backupdr.DataSourceGoogleCloudBackupDRBackup(),
"google_backup_dr_backup_plan_association": backupdr.DataSourceGoogleCloudBackupDRBackupPlanAssociation(),
"google_backup_dr_backup_plan": backupdr.DataSourceGoogleCloudBackupDRBackupPlan(),
"google_backup_dr_data_source": backupdr.DataSourceGoogleCloudBackupDRDataSource(),
{{- end }}
"google_backup_dr_backup": backupdr.DataSourceGoogleCloudBackupDRBackup(),
"google_backup_dr_data_source": backupdr.DataSourceGoogleCloudBackupDRDataSource(),
"google_backup_dr_backup_vault": backupdr.DataSourceGoogleCloudBackupDRBackupVault(),
"google_beyondcorp_app_connection": beyondcorp.DataSourceGoogleBeyondcorpAppConnection(),
"google_beyondcorp_app_connector": beyondcorp.DataSourceGoogleBeyondcorpAppConnector(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package backupdr
{{- if ne $.TargetVersionName "ga" }}

import (
"fmt"
Expand Down Expand Up @@ -171,5 +170,3 @@ func flattenDataSourceBackupDRBackupsBackupVaultId(v interface{}, d *schema.Reso
func flattenDataSourceBackupDRBackupsDataSourceId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

{{- end }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package backupdr_test
{{- if ne $.TargetVersionName "ga" }}

import (
"fmt"
Expand Down Expand Up @@ -51,5 +50,3 @@ data "google_backup_dr_backup" "foo" {

`, context)
}

{{- end }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package backupdr
{{- if ne $.TargetVersionName "ga" }}

import (
"fmt"
Expand Down Expand Up @@ -619,4 +618,3 @@ func flattenBackupDRDataSourceDataSourceBackupApplianceApplicationApplicationHos
func flattenBackupDRDataSourceDataSourceBackupApplianceApplicationApplicationHostId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package backupdr_test
{{- if ne $.TargetVersionName "ga" }}

import (
"fmt"
Expand Down Expand Up @@ -54,4 +53,3 @@ data "google_backup_dr_data_source" "foo" {

`, context)
}
{{- end }}
Loading

0 comments on commit a7af1b3

Please sign in to comment.