-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
ea6ea1d
commit 14d6266
Showing
5 changed files
with
117 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,25 @@ | ||
package google | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleComputeRouter() *schema.Resource { | ||
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeRouter().Schema) | ||
addRequiredFieldsToSchema(dsSchema, "name") | ||
addRequiredFieldsToSchema(dsSchema, "network") | ||
addOptionalFieldsToSchema(dsSchema, "region") | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceComputeRouterRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error { | ||
routerName := d.Get("name").(string) | ||
|
||
d.SetId(routerName) | ||
return resourceComputeRouterRead(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,49 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceComputeRouter(t *testing.T) { | ||
t.Parallel() | ||
name := acctest.RandomWithPrefix("router-test") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceComputeRouterConfig(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_compute_router.myrouter", "id", name), | ||
resource.TestCheckResourceAttr("data.google_compute_router.myrouter", "name", name), | ||
resource.TestCheckResourceAttr("data.google_compute_router.myrouter", "network", fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", getTestProjectFromEnv(), name)), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceComputeRouterConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_network" "foobar" { | ||
name = "%s" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_router" "foobar" { | ||
name = "%s" | ||
network = "${google_compute_network.foobar.name}" | ||
bgp { | ||
asn = 64514 | ||
} | ||
} | ||
data "google_compute_router" "myrouter" { | ||
name = "${google_compute_router.foobar.name}" | ||
network = "${google_compute_network.foobar.name}" | ||
} | ||
`, name, name) | ||
} |
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,39 @@ | ||
--- | ||
layout: "google" | ||
page_title: "Google: google_compute_router" | ||
sidebar_current: "docs-google-datasource-compute-router" | ||
description: |- | ||
Get a Cloud Router within GCE. | ||
--- | ||
|
||
# google\_compute\_router | ||
|
||
Get a router within GCE from its name and VPC. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_compute_router" "my-router" { | ||
name = "myrouter-us-east1" | ||
network = "my-network" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the router. | ||
|
||
* `network` - (Required) The VPC network on which this router lives. | ||
|
||
* `project` - (Optional) The ID of the project in which the resource | ||
belongs. If it is not provided, the provider project is used. | ||
|
||
* `region` - (Optional) The region this router has been created in. If | ||
unspecified, this defaults to the region configured in the provider. | ||
|
||
|
||
## Attributes Reference | ||
|
||
See [google_compute_router](https://www.terraform.io/docs/providers/google/r/compute_router.html) resource for details of the available attributes. |
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