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

Promote PSC global access to GA #14754

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/8013.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:note
compute: promoted `allowPscGlobalAccess` field to GA for resource `google_compute_forwarding_rule`
```
23 changes: 23 additions & 0 deletions google/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ regions.
Otherwise only allows access from clients in the same region as the
internal load balancer.`,
},
"allow_psc_global_access": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `This is used in PSC consumer ForwardingRule to control whether the PSC endpoint can be accessed from another region.`,
},
"backend_service": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -578,6 +584,12 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
} else if v, ok := d.GetOkExists("source_ip_ranges"); !tpgresource.IsEmptyValue(reflect.ValueOf(sourceIpRangesProp)) && (ok || !reflect.DeepEqual(v, sourceIpRangesProp)) {
obj["sourceIpRanges"] = sourceIpRangesProp
}
allowPscGlobalAccessProp, err := expandComputeForwardingRuleAllowPscGlobalAccess(d.Get("allow_psc_global_access"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("allow_psc_global_access"); ok || !reflect.DeepEqual(v, allowPscGlobalAccessProp) {
obj["allowPscGlobalAccess"] = allowPscGlobalAccessProp
}
regionProp, err := expandComputeForwardingRuleRegion(d.Get("region"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -797,6 +809,9 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
if err := d.Set("base_forwarding_rule", flattenComputeForwardingRuleBaseForwardingRule(res["baseForwardingRule"], d, config)); err != nil {
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}
if err := d.Set("allow_psc_global_access", flattenComputeForwardingRuleAllowPscGlobalAccess(res["allowPscGlobalAccess"], d, config)); err != nil {
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}
if err := d.Set("region", flattenComputeForwardingRuleRegion(res["region"], d, config)); err != nil {
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}
Expand Down Expand Up @@ -1171,6 +1186,10 @@ func flattenComputeForwardingRuleBaseForwardingRule(v interface{}, d *schema.Res
return v
}

func flattenComputeForwardingRuleAllowPscGlobalAccess(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeForwardingRuleRegion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1364,6 +1383,10 @@ func expandComputeForwardingRuleSourceIpRanges(v interface{}, d tpgresource.Terr
return v, nil
}

func expandComputeForwardingRuleAllowPscGlobalAccess(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeForwardingRuleRegion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
f, err := tpgresource.ParseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
Expand Down
124 changes: 124 additions & 0 deletions google/resource_compute_forwarding_rule_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,130 @@ resource "google_compute_subnetwork" "default" {
`, context)
}

func TestAccComputeForwardingRule_forwardingRuleVpcPscExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_forwardingRuleVpcPscExample(context),
},
{
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "region", "port_range", "target", "ip_address"},
},
},
})
}

func testAccComputeForwardingRule_forwardingRuleVpcPscExample(context map[string]interface{}) string {
return Nprintf(`
// Forwarding rule for VPC private service connect
resource "google_compute_forwarding_rule" "default" {
name = "tf-test-psc-endpoint%{random_suffix}"
region = "us-central1"
load_balancing_scheme = ""
target = google_compute_service_attachment.producer_service_attachment.id
network = google_compute_network.consumer_net.name
ip_address = google_compute_address.consumer_address.id
allow_psc_global_access = true
}

// Consumer service endpoint

resource "google_compute_network" "consumer_net" {
name = "tf-test-consumer-net%{random_suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "consumer_subnet" {
name = "tf-test-consumer-net%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.consumer_net.id
}

resource "google_compute_address" "consumer_address" {
name = "tf-test-website-ip%{random_suffix}-1"
region = "us-central1"
subnetwork = google_compute_subnetwork.consumer_subnet.id
address_type = "INTERNAL"
}


// Producer service attachment

resource "google_compute_network" "producer_net" {
name = "tf-test-producer-net%{random_suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "producer_subnet" {
name = "tf-test-producer-net%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.producer_net.id
}

resource "google_compute_subnetwork" "psc_producer_subnet" {
name = "tf-test-producer-psc-net%{random_suffix}"
ip_cidr_range = "10.1.0.0/16"
region = "us-central1"

purpose = "PRIVATE_SERVICE_CONNECT"
network = google_compute_network.producer_net.id
}

resource "google_compute_service_attachment" "producer_service_attachment" {
name = "tf-test-producer-service%{random_suffix}"
region = "us-central1"
description = "A service attachment configured with Terraform"

enable_proxy_protocol = true
connection_preference = "ACCEPT_AUTOMATIC"
nat_subnets = [google_compute_subnetwork.psc_producer_subnet.name]
target_service = google_compute_forwarding_rule.producer_target_service.id
}

resource "google_compute_forwarding_rule" "producer_target_service" {
name = "tf-test-producer-forwarding-rule%{random_suffix}"
region = "us-central1"

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.producer_service_backend.id
all_ports = true
network = google_compute_network.producer_net.name
subnetwork = google_compute_subnetwork.producer_subnet.name
}

resource "google_compute_region_backend_service" "producer_service_backend" {
name = "tf-test-producer-service-backend%{random_suffix}"
region = "us-central1"

health_checks = [google_compute_health_check.producer_service_health_check.id]
}

resource "google_compute_health_check" "producer_service_health_check" {
name = "tf-test-producer-service-health-check%{random_suffix}"

check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
`, context)
}

func TestAccComputeForwardingRule_forwardingRuleRegionalSteeringExample(t *testing.T) {
t.Parallel()

Expand Down
131 changes: 131 additions & 0 deletions google/resource_compute_forwarding_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@ func TestAccComputeForwardingRule_networkTier(t *testing.T) {
})
}

func TestAccComputeForwardingRule_forwardingRuleVpcPscExampleUpdate(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_forwardingRuleVpcPscExample(context),
},
{
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeForwardingRule_forwardingRuleVpcPscExampleUpdate(context),
},
{
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccComputeForwardingRule_forwardingRuleRegionalSteeringExampleUpdate(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -217,6 +249,105 @@ resource "google_compute_forwarding_rule" "foobar" {
`, poolName, ruleName)
}

func testAccComputeForwardingRule_forwardingRuleVpcPscExampleUpdate(context map[string]interface{}) string {
return Nprintf(`
// Forwarding rule for VPC private service connect
resource "google_compute_forwarding_rule" "default" {
name = "tf-test-psc-endpoint%{random_suffix}"
region = "us-central1"
load_balancing_scheme = ""
target = google_compute_service_attachment.producer_service_attachment.id
network = google_compute_network.consumer_net.name
ip_address = google_compute_address.consumer_address.id
allow_psc_global_access = false
}

// Consumer service endpoint

resource "google_compute_network" "consumer_net" {
name = "tf-test-consumer-net%{random_suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "consumer_subnet" {
name = "tf-test-consumer-net%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.consumer_net.id
}

resource "google_compute_address" "consumer_address" {
name = "tf-test-website-ip%{random_suffix}-1"
region = "us-central1"
subnetwork = google_compute_subnetwork.consumer_subnet.id
address_type = "INTERNAL"
}


// Producer service attachment

resource "google_compute_network" "producer_net" {
name = "tf-test-producer-net%{random_suffix}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "producer_subnet" {
name = "tf-test-producer-net%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.producer_net.id
}

resource "google_compute_subnetwork" "psc_producer_subnet" {
name = "tf-test-producer-psc-net%{random_suffix}"
ip_cidr_range = "10.1.0.0/16"
region = "us-central1"

purpose = "PRIVATE_SERVICE_CONNECT"
network = google_compute_network.producer_net.id
}

resource "google_compute_service_attachment" "producer_service_attachment" {
name = "tf-test-producer-service%{random_suffix}"
region = "us-central1"
description = "A service attachment configured with Terraform"

enable_proxy_protocol = true
connection_preference = "ACCEPT_AUTOMATIC"
nat_subnets = [google_compute_subnetwork.psc_producer_subnet.name]
target_service = google_compute_forwarding_rule.producer_target_service.id
}

resource "google_compute_forwarding_rule" "producer_target_service" {
name = "tf-test-producer-forwarding-rule%{random_suffix}"
region = "us-central1"

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.producer_service_backend.id
all_ports = true
network = google_compute_network.producer_net.name
subnetwork = google_compute_subnetwork.producer_subnet.name
}

resource "google_compute_region_backend_service" "producer_service_backend" {
name = "tf-test-producer-service-backend%{random_suffix}"
region = "us-central1"

health_checks = [google_compute_health_check.producer_service_health_check.id]
}

resource "google_compute_health_check" "producer_service_health_check" {
name = "tf-test-producer-service-health-check%{random_suffix}"

check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
`, context)
}

func testAccComputeForwardingRule_forwardingRuleRegionalSteeringExampleUpdate(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_forwarding_rule" "steering" {
Expand Down
Loading