-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Adding google_compute_network_peering datasource * Removing unused diffSuppress Signed-off-by: Modular Magician <magic-modules@google.com> Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
3105cd0
commit 82fee5e
Showing
5 changed files
with
164 additions
and
0 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-datasource | ||
`google_compute_network_peering` | ||
``` |
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,38 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const regexGCEName = "^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$" | ||
|
||
func dataSourceComputeNetworkPeering() *schema.Resource { | ||
|
||
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeNetworkPeering().Schema) | ||
addRequiredFieldsToSchema(dsSchema, "name", "network") | ||
|
||
dsSchema["name"].ValidateFunc = validateRegexp(regexGCEName) | ||
dsSchema["network"].ValidateFunc = validateRegexp(peerNetworkLinkRegex) | ||
return &schema.Resource{ | ||
Read: dataSourceComputeNetworkPeeringRead, | ||
Schema: dsSchema, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(4 * time.Minute), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceComputeNetworkPeeringRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
networkFieldValue, err := ParseNetworkFieldValue(d.Get("network").(string), d, config) | ||
if err != nil { | ||
return err | ||
} | ||
d.SetId(fmt.Sprintf("%s/%s", networkFieldValue.Name, d.Get("name").(string))) | ||
|
||
return resourceComputeNetworkPeeringRead(d, meta) | ||
} |
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,60 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceComputeNetworkPeering_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": randString(t, 10), | ||
} | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccComputeNetworkPeeringDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceComputeNetworkPeering_basic(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState("data.google_compute_network_peering.peering1_ds", "google_compute_network_peering.peering1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceComputeNetworkPeering_basic(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_compute_network_peering" "peering1" { | ||
name = "peering1-%{random_suffix}" | ||
network = google_compute_network.default.self_link | ||
peer_network = google_compute_network.other.self_link | ||
} | ||
resource "google_compute_network_peering" "peering2" { | ||
name = "peering2-%{random_suffix}" | ||
network = google_compute_network.other.self_link | ||
peer_network = google_compute_network.default.self_link | ||
} | ||
resource "google_compute_network" "default" { | ||
name = "foobar-%{random_suffix}" | ||
auto_create_subnetworks = "false" | ||
} | ||
resource "google_compute_network" "other" { | ||
name = "other-%{random_suffix}" | ||
auto_create_subnetworks = "false" | ||
} | ||
data "google_compute_network_peering" "peering1_ds" { | ||
name = google_compute_network_peering.peering1.name | ||
network = google_compute_network_peering.peering1.network | ||
} | ||
`, context) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
subcategory: "Compute Engine" | ||
page_title: "Google: google_compute_network_peering" | ||
description: |- | ||
Get information of a specified compute network peering. | ||
--- | ||
|
||
# google\_compute\_network\_peering | ||
|
||
Get information of a specified compute network peering. For more information see | ||
[the official documentation](https://cloud.google.com/compute/docs/vpc/vpc-peering) | ||
and | ||
[API](https://cloud.google.com/compute/docs/reference/latest/networks). | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "google_compute_network_peering" "peering1" { | ||
name = "peering1" | ||
network = google_compute_network.default.self_link | ||
peer_network = google_compute_network.other.self_link | ||
} | ||
resource "google_compute_network_peering" "peering2" { | ||
name = "peering2" | ||
network = google_compute_network.other.self_link | ||
peer_network = google_compute_network.default.self_link | ||
} | ||
resource "google_compute_network" "default" { | ||
name = "foobar" | ||
auto_create_subnetworks = "false" | ||
} | ||
resource "google_compute_network" "other" { | ||
name = "other" | ||
auto_create_subnetworks = "false" | ||
} | ||
data "google_compute_network_peering" "peering1_ds" { | ||
name = google_compute_network_peering.peering1.name | ||
network = google_compute_network_peering.peering1.network | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) Name of the peering. | ||
|
||
* `network` - (Required) The primary network of the peering. | ||
|
||
## Attributes Reference | ||
|
||
See [google_compute_network_peering](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network_peering#argument-reference) resource for details of the available attributes. | ||
|
||
## Timeouts | ||
|
||
This datasource provides the following | ||
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: | ||
|
||
- `read` - Default is 4 minutes. |