Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add self_link to subnetwork datasource #1377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"description": {
"self_link": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"self_link": {
"description": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -75,15 +74,10 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
}
region, err := getRegion(d, config)
project, region, name, err := GetRegionalResourcePropertiesFromSelfLinkOrSchema(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 {
Expand All @@ -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
}

Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
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
when adding an alias IP range to a VM instance.

* `ip_cidr_range` - The range of IP addresses belonging to this subnetwork
secondary range.
secondary range.