Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main feature branch 6.0.0 #18552

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
cloud.google.com/go/bigtable v1.24.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.67.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.68.0
github.com/apparentlymart/go-cidr v1.1.0
github.com/davecgh/go-spew v1.1.1
github.com/dnaeon/go-vcr v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ cloud.google.com/go/longrunning v0.5.7/go.mod h1:8GClkudohy1Fxm3owmBGid8W0pSgodE
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.67.0 h1:FBKsgWIOEdtpx2YuF+aBH33K0Ih25D3xuKyp9peH4jc=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.67.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.68.0 h1:LIPIYi4hy7ttUSrziY/TYwMDuEvvV593n80kRmz6nZ4=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.68.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0=
Expand Down
2 changes: 0 additions & 2 deletions google/functions/location_from_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

func TestAccProviderFunction_location_from_id(t *testing.T) {
t.Parallel()
// Skipping due to requiring TF 1.8.0 in VCR systems : https://github.com/hashicorp/terraform-provider-google/issues/17451
acctest.SkipIfVcr(t)

location := "us-central1"
locationRegex := regexp.MustCompile(fmt.Sprintf("^%s$", location))
Expand Down
2 changes: 0 additions & 2 deletions google/functions/name_from_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

func TestAccProviderFunction_name_from_id(t *testing.T) {
t.Parallel()
// Skipping due to requiring TF 1.8.0 in VCR systems : https://github.com/hashicorp/terraform-provider-google/issues/17451
acctest.SkipIfVcr(t)

context := map[string]interface{}{
"function_name": "name_from_id",
Expand Down
2 changes: 0 additions & 2 deletions google/functions/project_from_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

func TestAccProviderFunction_project_from_id(t *testing.T) {
t.Parallel()
// Skipping due to requiring TF 1.8.0 in VCR systems : https://github.com/hashicorp/terraform-provider-google/issues/17451
acctest.SkipIfVcr(t)

projectId := envvar.GetTestProjectFromEnv()
projectIdRegex := regexp.MustCompile(fmt.Sprintf("^%s$", projectId))
Expand Down
2 changes: 0 additions & 2 deletions google/functions/region_from_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

func TestAccProviderFunction_region_from_id(t *testing.T) {
t.Parallel()
// Skipping due to requiring TF 1.8.0 in VCR systems : https://github.com/hashicorp/terraform-provider-google/issues/17451
acctest.SkipIfVcr(t)

region := envvar.GetTestRegionFromEnv()
regionRegex := regexp.MustCompile(fmt.Sprintf("^%s$", region))
Expand Down
18 changes: 10 additions & 8 deletions google/functions/region_from_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package functions
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/function"
)
Expand Down Expand Up @@ -37,23 +38,24 @@ func (f RegionFromZoneFunction) Definition(ctx context.Context, req function.Def

func (f RegionFromZoneFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
// Load arguments from function call
var arg0 string
resp.Error = function.ConcatFuncErrors(req.Arguments.GetArgument(ctx, 0, &arg0))
var zone string
resp.Error = function.ConcatFuncErrors(req.Arguments.GetArgument(ctx, 0, &zone))
if resp.Error != nil {
return
}

if arg0 == "" {
if zone == "" {
err := function.NewArgumentFuncError(0, "The input string cannot be empty.")
resp.Error = function.ConcatFuncErrors(err)
return
}

if arg0[len(arg0)-2] != '-' {
err := function.NewArgumentFuncError(0, fmt.Sprintf("The input string \"%s\" is not a valid zone name.", arg0))
zoneParts := strings.Split(zone, "-")

if len(zoneParts) < 3 {
err := function.NewArgumentFuncError(0, fmt.Sprintf("The input string \"%s\" is not a valid zone name.", zone))
resp.Error = function.ConcatFuncErrors(err)
return
} else {
resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, strings.Join(zoneParts[:len(zoneParts)-1], "-")))
}

resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, arg0[:len(arg0)-2]))
}
3 changes: 1 addition & 2 deletions google/functions/region_from_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (

func TestAccProviderFunction_region_from_zone(t *testing.T) {
t.Parallel()
// Skipping due to requiring TF 1.8.0 in VCR systems : https://github.com/hashicorp/terraform-provider-google/issues/17451
acctest.SkipIfVcr(t)

projectZone := "us-central1-a"
projectRegion := "us-central1"
projectRegionRegex := regexp.MustCompile(fmt.Sprintf("^%s$", projectRegion))
Expand Down
2 changes: 0 additions & 2 deletions google/functions/zone_from_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

func TestAccProviderFunction_zone_from_id(t *testing.T) {
t.Parallel()
// Skipping due to requiring TF 1.8.0 in VCR systems : https://github.com/hashicorp/terraform-provider-google/issues/17451
acctest.SkipIfVcr(t)

zone := envvar.GetTestZoneFromEnv()
zoneRegex := regexp.MustCompile(fmt.Sprintf("^%s$", zone))
Expand Down
5 changes: 3 additions & 2 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 426
// Generated resources: 427
// Generated IAM resources: 249
// Total generated resources: 675
// Total generated resources: 676
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -610,6 +610,7 @@ var generatedResources = map[string]*schema.Resource{
"google_compute_interconnect_attachment": compute.ResourceComputeInterconnectAttachment(),
"google_compute_managed_ssl_certificate": compute.ResourceComputeManagedSslCertificate(),
"google_compute_network": compute.ResourceComputeNetwork(),
"google_compute_network_attachment": compute.ResourceComputeNetworkAttachment(),
"google_compute_network_endpoint": compute.ResourceComputeNetworkEndpoint(),
"google_compute_network_endpoint_group": compute.ResourceComputeNetworkEndpointGroup(),
"google_compute_network_endpoints": compute.ResourceComputeNetworkEndpoints(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,14 +1099,13 @@ func flattenAccessContextManagerServicePerimetersServicePerimeters(v interface{}
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
apiData := make([]map[string]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{}{
apiData = append(apiData, map[string]interface{}{
"name": flattenAccessContextManagerServicePerimetersServicePerimetersName(original["name"], d, config),
"title": flattenAccessContextManagerServicePerimetersServicePerimetersTitle(original["title"], d, config),
"description": flattenAccessContextManagerServicePerimetersServicePerimetersDescription(original["description"], d, config),
Expand All @@ -1118,8 +1117,19 @@ func flattenAccessContextManagerServicePerimetersServicePerimeters(v interface{}
"use_explicit_dry_run_spec": flattenAccessContextManagerServicePerimetersServicePerimetersUseExplicitDryRunSpec(original["useExplicitDryRunSpec"], d, config),
})
}
return transformed
configData := []map[string]interface{}{}
for _, item := range d.Get("service_perimeters").([]interface{}) {
configData = append(configData, item.(map[string]interface{}))
}
sorted, err := tpgresource.SortMapsByConfigOrder(configData, apiData, "name")
if err != nil {
log.Printf("[ERROR] Could not sort API response value: %s", err)
return v
}

return sorted
}

func flattenAccessContextManagerServicePerimetersServicePerimetersName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,28 @@ func testAccAccessContextManagerServicePerimeters_basicTest(t *testing.T) {
Config: testAccAccessContextManagerServicePerimeters_basic(org, "my policy", "level", "storage_perimeter", "bigtable_perimeter", "bigquery_omni_perimeter"),
},
{
ResourceName: "google_access_context_manager_service_perimeters.test-access",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_access_context_manager_service_perimeters.test-access",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_perimeters"},
},
{
Config: testAccAccessContextManagerServicePerimeters_update(org, "my policy", "level", "storage_perimeter", "bigquery_perimeter", "bigtable_perimeter", "bigquery_omni_perimeter"),
},
{
ResourceName: "google_access_context_manager_service_perimeters.test-access",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_access_context_manager_service_perimeters.test-access",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_perimeters"},
},
{
Config: testAccAccessContextManagerServicePerimeters_empty(org, "my policy", "level"),
},
{
ResourceName: "google_access_context_manager_service_perimeters.test-access",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_access_context_manager_service_perimeters.test-access",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_perimeters"},
},
},
})
Expand Down
17 changes: 16 additions & 1 deletion google/services/bigtable/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ func ResourceBigtableGCPolicy() *schema.Resource {
in a replicated instance. Possible values are: "ABANDON".`,
ValidateFunc: validation.StringInSlice([]string{"ABANDON", ""}, false),
},

"ignore_warnings": {
Type: schema.TypeBool,
Optional: true,
Description: `Allows ignoring warnings when updating the GC policy. This can be used
to increase the gc policy on replicated clusters. Doing this may make clusters be
inconsistent for a longer period of time, before using this make sure you understand
the risks listed at https://cloud.google.com/bigtable/docs/garbage-collection#increasing`,
Default: false,
},
},
UseJSONNumber: true,
}
Expand Down Expand Up @@ -255,9 +265,14 @@ func resourceBigtableGCPolicyUpsert(d *schema.ResourceData, meta interface{}) er

tableName := d.Get("table").(string)
columnFamily := d.Get("column_family").(string)
ignoreWarnings := d.Get("ignore_warnings").(bool)
updateOpts := []bigtable.GCPolicyOption{}
if ignoreWarnings {
updateOpts = append(updateOpts, bigtable.IgnoreWarnings())
}

retryFunc := func() error {
reqErr := c.SetGCPolicy(ctx, tableName, columnFamily, gcPolicy)
reqErr := c.SetGCPolicyWithOptions(ctx, tableName, columnFamily, gcPolicy, updateOpts...)
return reqErr
}
// The default create timeout is 20 minutes.
Expand Down
80 changes: 80 additions & 0 deletions google/services/bigtable/resource_bigtable_gc_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@ func TestAccBigtableGCPolicy_basic(t *testing.T) {
})
}

func TestAccBigtableGCPolicy_ignoreWarnings(t *testing.T) {
// bigtable instance does not use the shared HTTP client, this test creates an instance
acctest.SkipIfVcr(t)
t.Parallel()

instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
familyName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
cluster1Name := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
cluster2Name := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))

gcRulesOriginal := `{"rules":[{"max_age":"10h"}]}`
gcRulesNew := `{"rules":[{"max_age":"12h"}]}`

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigtableGCPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, familyName, cluster1Name, cluster2Name, gcRulesOriginal, false),
Check: resource.ComposeTestCheckFunc(
testAccBigtableGCPolicyExists(t, "google_bigtable_gc_policy.policy", true),
resource.TestCheckResourceAttr("google_bigtable_gc_policy.policy", "gc_rules", gcRulesOriginal),
),
},
{
Config: testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, familyName, cluster1Name, cluster2Name, gcRulesNew, true),
Check: resource.ComposeTestCheckFunc(
testAccBigtableGCPolicyExists(t, "google_bigtable_gc_policy.policy", true),
resource.TestCheckResourceAttr("google_bigtable_gc_policy.policy", "gc_rules", gcRulesNew),
),
},
},
})
}

func TestAccBigtableGCPolicy_abandoned(t *testing.T) {
// bigtable instance does not use the shared HTTP client, this test creates an instance
acctest.SkipIfVcr(t)
Expand Down Expand Up @@ -565,6 +602,49 @@ resource "google_bigtable_gc_policy" "policy" {
`, instanceName, instanceName, tableName, family, family)
}

func testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, family string, cluster1 string, cluster2 string, gcRule string, ignoreWarnings bool) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"

cluster {
cluster_id = "%s"
num_nodes = 1
zone = "us-central1-b"
}

cluster {
cluster_id = "%s"
num_nodes = 1
zone = "us-central1-c"
}

deletion_protection = false
}

resource "google_bigtable_table" "table" {
name = "%s"
instance_name = google_bigtable_instance.instance.id

column_family {
family = "%s"
}
}

resource "google_bigtable_gc_policy" "policy" {
instance_name = google_bigtable_instance.instance.id
table = google_bigtable_table.table.name
column_family = "%s"
gc_rules = <<EOF
%s
EOF

ignore_warnings = %t
deletion_policy = "ABANDON"
}
`, instanceName, cluster1, cluster2, tableName, family, family, gcRule, ignoreWarnings)
}

func testAccBigtableGCPolicyToBeAbandoned(instanceName, tableName, family string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
Expand Down
Loading