-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ServiceConnectionPolicies resource in NetworkConnectivity. (#8273
) (#15381) * adding both resources, basic test for serviceClass it's working, need to fix the test scenario for policy * fix the test scenario and the service class resource properties * adding a testing update, just adding the labels for the resource * added the resource service connection map, and it's basic test, need to evaluate * Revert "added the resource service connection map, and it's basic test, need to evaluate" This reverts commit 4240e1d81e5901221cee1f1db7c03c8fbc58e3a6. * removing the service class in one test scenario and using a static value * fix a typo * removing serviceClass and fix the tests * removing ga tag and updatinga etag for fingerprint type * updating the code, to remove the static value from the docs, need to test * adding a file to tpgtools override at product level * adding function to help with env var, but the patch on tests it's failing * adding the variable to be used in the docs * fixing the test, the network field cannot be immutable * removing the env_var service class and adding a static value * updating the value used from tests and documentation * removing unused resources for docs and tests * fix typos, not used variables and run the fmt * adding description to the basic test * fixed yaml variable override * removing unused resources for tests, and making the test fails with network as immutable * adding encoder to help network field be immutable and be sent on patch method Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
1dced78
commit d91a1eb
Showing
15 changed files
with
1,277 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
google_network_connectivity_service_connection_policy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
google/resource_network_connectivity_service_connection_policies_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestAccNetworkConnectivityServiceConnectionPolicy_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"networkProducerName": fmt.Sprintf("tf-test-network-%s", RandString(t, 10)), | ||
"subnetworkProducerName1": fmt.Sprintf("tf-test-subnet-producer-%s", RandString(t, 10)), | ||
"subnetworkProducerName2": fmt.Sprintf("tf-test-subnet-producer-%s", RandString(t, 10)), | ||
"serviceConnectionPolicyName": fmt.Sprintf("tf-test-service-connection-policy-%s", RandString(t, 10)), | ||
} | ||
|
||
VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckNetworkConnectivityServiceConnectionPolicyDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccNetworkConnectivityServiceConnectionPolicy_basic(context), | ||
}, | ||
{ | ||
ResourceName: "google_network_connectivity_service_connection_policy.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccNetworkConnectivityServiceConnectionPolicy_update(context), | ||
}, | ||
{ | ||
ResourceName: "google_network_connectivity_service_connection_policy.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccNetworkConnectivityServiceConnectionPolicy_basic(context), | ||
}, | ||
{ | ||
ResourceName: "google_network_connectivity_service_connection_policy.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNetworkConnectivityServiceConnectionPolicy_basic(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_compute_network" "producer_net" { | ||
name = "%{networkProducerName}" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "producer_subnet" { | ||
name = "%{subnetworkProducerName1}" | ||
ip_cidr_range = "10.0.0.0/16" | ||
region = "us-central1" | ||
network = google_compute_network.producer_net.id | ||
} | ||
resource "google_network_connectivity_service_connection_policy" "default" { | ||
name = "%{serviceConnectionPolicyName}" | ||
location = "us-central1" | ||
service_class = "gcp-memorystore-redis" | ||
network = google_compute_network.producer_net.id | ||
psc_config { | ||
subnetworks = [google_compute_subnetwork.producer_subnet.id] | ||
limit = 2 | ||
} | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccNetworkConnectivityServiceConnectionPolicy_update(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_compute_network" "producer_net" { | ||
name = "%{networkProducerName}" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "producer_subnet1" { | ||
name = "%{subnetworkProducerName2}" | ||
ip_cidr_range = "10.1.0.0/16" | ||
region = "us-central1" | ||
network = google_compute_network.producer_net.id | ||
} | ||
resource "google_network_connectivity_service_connection_policy" "default" { | ||
name = "%{serviceConnectionPolicyName}" | ||
location = "us-central1" | ||
service_class = "gcp-memorystore-redis" | ||
network = google_compute_network.producer_net.id | ||
psc_config { | ||
subnetworks = [google_compute_subnetwork.producer_subnet1.id] | ||
limit = 4 | ||
} | ||
labels = { | ||
foo = "bar" | ||
} | ||
} | ||
`, context) | ||
} |
124 changes: 124 additions & 0 deletions
124
google/resource_network_connectivity_service_connection_policy_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func TestAccNetworkConnectivityServiceConnectionPolicy_networkConnectivityPolicyBasicExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"service_class_name": "gcp-memorystore-redis", | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckNetworkConnectivityServiceConnectionPolicyDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccNetworkConnectivityServiceConnectionPolicy_networkConnectivityPolicyBasicExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_network_connectivity_service_connection_policy.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"name", "location"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNetworkConnectivityServiceConnectionPolicy_networkConnectivityPolicyBasicExample(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
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-subnet%{random_suffix}" | ||
ip_cidr_range = "10.0.0.0/16" | ||
region = "us-central1" | ||
network = google_compute_network.producer_net.id | ||
} | ||
resource "google_network_connectivity_service_connection_policy" "default" { | ||
name = "tf-test-my-network-connectivity-policy%{random_suffix}" | ||
location = "us-central1" | ||
service_class = "%{service_class_name}" | ||
description = "my basic service connection policy" | ||
network = google_compute_network.producer_net.id | ||
psc_config { | ||
subnetworks = [google_compute_subnetwork.producer_subnet.id] | ||
limit = 2 | ||
} | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccCheckNetworkConnectivityServiceConnectionPolicyDestroyProducer(t *testing.T) func(s *terraform.State) error { | ||
return func(s *terraform.State) error { | ||
for name, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_network_connectivity_service_connection_policy" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := acctest.GoogleProviderConfig(t) | ||
|
||
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{NetworkConnectivityBasePath}}projects/{{project}}/locations/{{location}}/serviceConnectionPolicies/{{name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
if config.BillingProject != "" { | ||
billingProject = config.BillingProject | ||
} | ||
|
||
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "GET", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: config.UserAgent, | ||
}) | ||
if err == nil { | ||
return fmt.Errorf("NetworkConnectivityServiceConnectionPolicy still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.