mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Add self_link to subnetwork datasource (#3040)
Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
parent
a76eefdf7f
commit
8fb69aea88
|
@ -14,14 +14,13 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
|
|||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
},
|
||||
"self_link": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
@ -75,15 +74,10 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
|
|||
func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
|
||||
project, err := getProject(d, config)
|
||||
project, region, name, err := GetRegionalResourcePropertiesFromSelfLinkOrSchema(d, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
region, err := getRegion(d, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name := d.Get("name").(string)
|
||||
|
||||
subnetwork, err := config.clientCompute.Subnetworks.Get(project, region, name).Do()
|
||||
if err != nil {
|
||||
|
@ -98,12 +92,9 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac
|
|||
d.Set("network", subnetwork.Network)
|
||||
d.Set("project", project)
|
||||
d.Set("region", region)
|
||||
// Flattening code defined in resource_compute_subnetwork.go
|
||||
d.Set("secondary_ip_range", flattenSecondaryRanges(subnetwork.SecondaryIpRanges))
|
||||
|
||||
//Subnet id creation is defined in resource_compute_subnetwork.go
|
||||
subnetwork.Region = region
|
||||
d.SetId(createSubnetID(subnetwork))
|
||||
d.SetId(fmt.Sprintf("%s/%s", region, name))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -119,7 +110,3 @@ func flattenSecondaryRanges(secondaryRanges []*compute.SubnetworkSecondaryRange)
|
|||
}
|
||||
return secondaryRangesSchema
|
||||
}
|
||||
|
||||
func createSubnetID(s *compute.Subnetwork) string {
|
||||
return fmt.Sprintf("%s/%s", s.Region, s.Name)
|
||||
}
|
||||
|
|
|
@ -72,11 +72,11 @@ func testAccDataSourceGoogleSubnetworkCheck(data_source_name string, resource_na
|
|||
|
||||
func testAccDataSourceGoogleSubnetwork() string {
|
||||
return fmt.Sprintf(`
|
||||
|
||||
resource "google_compute_network" "foobar" {
|
||||
name = "%s"
|
||||
description = "my-description"
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "foobar" {
|
||||
name = "subnetwork-test"
|
||||
description = "my-description"
|
||||
|
@ -92,5 +92,9 @@ resource "google_compute_subnetwork" "foobar" {
|
|||
data "google_compute_subnetwork" "my_subnetwork" {
|
||||
name = "${google_compute_subnetwork.foobar.name}"
|
||||
}
|
||||
|
||||
data "google_compute_subnetwork" "my_subnetwork_self_link" {
|
||||
self_link = "${google_compute_subnetwork.foobar.self_link}"
|
||||
}
|
||||
`, acctest.RandomWithPrefix("network-test"))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ Get a subnetwork within GCE from its name and region.
|
|||
|
||||
## Example Usage
|
||||
|
||||
```tf
|
||||
```hcl
|
||||
data "google_compute_subnetwork" "my-subnetwork" {
|
||||
name = "default-us-east1"
|
||||
region = "us-east1"
|
||||
|
@ -23,9 +23,11 @@ data "google_compute_subnetwork" "my-subnetwork" {
|
|||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - The name of the subnetwork.
|
||||
* `self_link` - (Optional) The self link of the subnetwork. If `self_link` is
|
||||
specified, `name`, `project`, and `region` are ignored.
|
||||
|
||||
- - -
|
||||
* `name` - (Optional) The name of the subnetwork. One of `name` or `self_link`
|
||||
must be specified.
|
||||
|
||||
* `project` - (Optional) The ID of the project in which the resource belongs. If it
|
||||
is not provided, the provider project is used.
|
||||
|
@ -54,8 +56,6 @@ In addition to the arguments listed above, the following attributes are exported
|
|||
* `secondary_ip_range` - An array of configurations for secondary IP ranges for
|
||||
VM instances contained in this subnetwork. Structure is documented below.
|
||||
|
||||
* `self_link` - The URI of the created resource.
|
||||
|
||||
The `secondary_ip_range` block supports:
|
||||
|
||||
* `range_name` - The name associated with this subnetwork secondary range, used
|
||||
|
|
Loading…
Reference in New Issue
Block a user