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{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Optional: true,
|
||||||
},
|
|
||||||
|
|
||||||
"description": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Computed: true,
|
|
||||||
},
|
},
|
||||||
"self_link": {
|
"self_link": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
@ -75,15 +74,10 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
|
||||||
func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) error {
|
func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
config := meta.(*Config)
|
config := meta.(*Config)
|
||||||
|
|
||||||
project, err := getProject(d, config)
|
project, region, name, err := GetRegionalResourcePropertiesFromSelfLinkOrSchema(d, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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()
|
subnetwork, err := config.clientCompute.Subnetworks.Get(project, region, name).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -98,12 +92,9 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac
|
||||||
d.Set("network", subnetwork.Network)
|
d.Set("network", subnetwork.Network)
|
||||||
d.Set("project", project)
|
d.Set("project", project)
|
||||||
d.Set("region", region)
|
d.Set("region", region)
|
||||||
// Flattening code defined in resource_compute_subnetwork.go
|
|
||||||
d.Set("secondary_ip_range", flattenSecondaryRanges(subnetwork.SecondaryIpRanges))
|
d.Set("secondary_ip_range", flattenSecondaryRanges(subnetwork.SecondaryIpRanges))
|
||||||
|
|
||||||
//Subnet id creation is defined in resource_compute_subnetwork.go
|
d.SetId(fmt.Sprintf("%s/%s", region, name))
|
||||||
subnetwork.Region = region
|
|
||||||
d.SetId(createSubnetID(subnetwork))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +110,3 @@ func flattenSecondaryRanges(secondaryRanges []*compute.SubnetworkSecondaryRange)
|
||||||
}
|
}
|
||||||
return secondaryRangesSchema
|
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 {
|
func testAccDataSourceGoogleSubnetwork() string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
|
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "%s"
|
||||||
description = "my-description"
|
description = "my-description"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "subnetwork-test"
|
name = "subnetwork-test"
|
||||||
description = "my-description"
|
description = "my-description"
|
||||||
|
@ -92,5 +92,9 @@ resource "google_compute_subnetwork" "foobar" {
|
||||||
data "google_compute_subnetwork" "my_subnetwork" {
|
data "google_compute_subnetwork" "my_subnetwork" {
|
||||||
name = "${google_compute_subnetwork.foobar.name}"
|
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"))
|
`, acctest.RandomWithPrefix("network-test"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ Get a subnetwork within GCE from its name and region.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
```tf
|
```hcl
|
||||||
data "google_compute_subnetwork" "my-subnetwork" {
|
data "google_compute_subnetwork" "my-subnetwork" {
|
||||||
name = "default-us-east1"
|
name = "default-us-east1"
|
||||||
region = "us-east1"
|
region = "us-east1"
|
||||||
|
@ -23,9 +23,11 @@ data "google_compute_subnetwork" "my-subnetwork" {
|
||||||
|
|
||||||
The following arguments are supported:
|
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
|
* `project` - (Optional) The ID of the project in which the resource belongs. If it
|
||||||
is not provided, the provider project is used.
|
is not provided, the provider project is used.
|
||||||
|
@ -54,12 +56,10 @@ In addition to the arguments listed above, the following attributes are exported
|
||||||
* `secondary_ip_range` - An array of configurations for secondary IP ranges for
|
* `secondary_ip_range` - An array of configurations for secondary IP ranges for
|
||||||
VM instances contained in this subnetwork. Structure is documented below.
|
VM instances contained in this subnetwork. Structure is documented below.
|
||||||
|
|
||||||
* `self_link` - The URI of the created resource.
|
|
||||||
|
|
||||||
The `secondary_ip_range` block supports:
|
The `secondary_ip_range` block supports:
|
||||||
|
|
||||||
* `range_name` - The name associated with this subnetwork secondary range, used
|
* `range_name` - The name associated with this subnetwork secondary range, used
|
||||||
when adding an alias IP range to a VM instance.
|
when adding an alias IP range to a VM instance.
|
||||||
|
|
||||||
* `ip_cidr_range` - The range of IP addresses belonging to this subnetwork
|
* `ip_cidr_range` - The range of IP addresses belonging to this subnetwork
|
||||||
secondary range.
|
secondary range.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user