Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-google

* 'master' of https://github.com/olvesh/terraform-provider-google: (24 commits)
  Cleanup after v1.14.0 release
  v1.14.0
  Update CHANGELOG.md
  Add new google_compute_regions (hashicorp#1603)
  Update CHANGELOG.md
  Fix forwarding rule data source test (hashicorp#1606)
  Update CHANGELOG.md
  Fix redis authorized network and tests. The Redis API currently only accepts partial links. The tests weren't failing because they weren't actually using the network (oops). There were a few other test issues that I fixed while I was there. Fixes hashicorp#1571. (hashicorp#1599)
  update auth docs (hashicorp#1587)
  Fix network_tier tests.
  Add documentation for network tier (hashicorp#1593)
  Warn about ip_version with ip_address in global forwarding rule (hashicorp#616)
  Update CHANGELOG.md
  add support for network tiers (hashicorp#1530)
  Update CHANGELOG.md
  Allow using in repo configuration for cloudbuild trigger (hashicorp#1557)
  Update CHANGELOG.md
  add update support for redis (hashicorp#1590)
  Update CHANGELOG.md
  Added GCP Netblock Data Source (hashicorp#1416) (hashicorp#1580)
  ...
  • Loading branch information
Olve S. Hansen committed Jun 8, 2018
2 parents 189c9f9 + 8b28f4c commit a223776
Show file tree
Hide file tree
Showing 38 changed files with 1,464 additions and 189 deletions.
44 changes: 26 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
## 1.13.1 (Unreleased)
## 1.14.1 (Unreleased)
## 1.14.0 (June 07, 2018)

FEATURES:
* **New Datasource**: `google_service_account` [GH-1535]
* **New Datasource**: `google_service_account_key` [GH-1535]
* **New Datasource**: `google_service_account` ([#1535](https://github.com/terraform-providers/terraform-provider-google/issues/1535))
* **New Datasource**: `google_service_account_key` ([#1535](https://github.com/terraform-providers/terraform-provider-google/issues/1535))
* **New Datasource**: `google_netblock_ip_ranges` ([#1580](https://github.com/terraform-providers/terraform-provider-google/issues/1580))
* **New Datasource**: `google_compute_regions` ([#1603](https://github.com/terraform-providers/terraform-provider-google/issues/1603))

IMPROVEMENTS:
* compute: As part of migrating `google_compute_disk` to be autogenerated, enabled encrypted source snapshot & images. [GH-1521].
* compute: Accept subnetwork name only in `google_forwarding_rule` [GH-1552]
* compute: Add disabled property to `google_compute_firewall` [GH-1536]
* compute: Add support for custom request headers in `google_compute_backend_service` [GH-1537]
* compute: Add support for `ssl_policy` to `google_compute_target_ssl_proxy` [GH-1568]
* cloudbuild: Use the project defined in `trigger_template` when creating a `google_cloudbuild_trigger` [GH-1556]
* kms: Add basic update for `google_kms_crypto_key` resource [GH-1511]
* project: Use default provider project for `google_project_services` if project field is empty [GH-1553]
* project: Added support for restoring default organization policies [GH-1477]
* project: Handle spurious Cloud API errors and performance issues for `google_project_service(s)` [GH-1565]
* sql: Add labels support in `sql_database_instance` [GH-1567]
* compute: As part of migrating `google_compute_disk` to be autogenerated, enabled encrypted source snapshot & images. [[#1521](https://github.com/terraform-providers/terraform-provider-google/issues/1521)].
* compute: Accept subnetwork name only in `google_forwarding_rule` ([#1552](https://github.com/terraform-providers/terraform-provider-google/issues/1552))
* compute: Add disabled property to `google_compute_firewall` ([#1536](https://github.com/terraform-providers/terraform-provider-google/issues/1536))
* compute: Add support for custom request headers in `google_compute_backend_service` ([#1537](https://github.com/terraform-providers/terraform-provider-google/issues/1537))
* compute: Add support for `ssl_policy` to `google_compute_target_ssl_proxy` ([#1568](https://github.com/terraform-providers/terraform-provider-google/issues/1568))
* compute: Add support for `version`s in instance group manager ([#1499](https://github.com/terraform-providers/terraform-provider-google/issues/1499))
* compute: Add support for `network_tier` to address, instance and instance_template ([#1530](https://github.com/terraform-providers/terraform-provider-google/issues/1530))
* cloudbuild: Use the project defined in `trigger_template` when creating a `google_cloudbuild_trigger` ([#1556](https://github.com/terraform-providers/terraform-provider-google/issues/1556))
* cloudbuild: Support configuration file in repository for `google_cloudbuild_trigger` ([#1557](https://github.com/terraform-providers/terraform-provider-google/issues/1557))
* kms: Add basic update for `google_kms_crypto_key` resource ([#1511](https://github.com/terraform-providers/terraform-provider-google/issues/1511))
* project: Use default provider project for `google_project_services` if project field is empty ([#1553](https://github.com/terraform-providers/terraform-provider-google/issues/1553))
* project: Added support for restoring default organization policies ([#1477](https://github.com/terraform-providers/terraform-provider-google/issues/1477))
* project: Handle spurious Cloud API errors and performance issues for `google_project_service(s)` ([#1565](https://github.com/terraform-providers/terraform-provider-google/issues/1565))
* redis: Add update support for Redis Instances ([#1590](https://github.com/terraform-providers/terraform-provider-google/issues/1590))
* sql: Add labels support in `sql_database_instance` ([#1567](https://github.com/terraform-providers/terraform-provider-google/issues/1567))

BUG FIXES:
* dns: Suppress diff for ipv6 address in `google_dns_record_set` [GH-1551]
* storage: Support removing a label in `google_storage_bucket` [GH-1550]
* compute: Fix perpetual diff caused by the `google_instance_group` self_link in `google_regional_instance_group_manager` [GH-1549]
* project: Retry while listing enabled services [GH-1573]
* dns: Suppress diff for ipv6 address in `google_dns_record_set` ([#1551](https://github.com/terraform-providers/terraform-provider-google/issues/1551))
* storage: Support removing a label in `google_storage_bucket` ([#1550](https://github.com/terraform-providers/terraform-provider-google/issues/1550))
* compute: Fix perpetual diff caused by the `google_instance_group` self_link in `google_regional_instance_group_manager` ([#1549](https://github.com/terraform-providers/terraform-provider-google/issues/1549))
* project: Retry while listing enabled services ([#1573](https://github.com/terraform-providers/terraform-provider-google/issues/1573))
* redis: Allow self links for redis authorized network ([#1599](https://github.com/terraform-providers/terraform-provider-google/issues/1599))

## 1.13.0 (May 24, 2018)

Expand Down
6 changes: 4 additions & 2 deletions google/compute_instance_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func flattenAccessConfigs(accessConfigs []*computeBeta.AccessConfig) ([]map[stri
for i, ac := range accessConfigs {
flattened[i] = map[string]interface{}{
"nat_ip": ac.NatIP,
"network_tier": ac.NetworkTier,
"assigned_nat_ip": ac.NatIP,
}
if ac.SetPublicPtr {
Expand Down Expand Up @@ -103,8 +104,9 @@ func expandAccessConfigs(configs []interface{}) []*computeBeta.AccessConfig {
for i, raw := range configs {
data := raw.(map[string]interface{})
acs[i] = &computeBeta.AccessConfig{
Type: "ONE_TO_ONE_NAT",
NatIP: data["nat_ip"].(string),
Type: "ONE_TO_ONE_NAT",
NatIP: data["nat_ip"].(string),
NetworkTier: data["network_tier"].(string),
}
if ptr, ok := data["public_ptr_domain_name"]; ok && ptr != "" {
acs[i].SetPublicPtr = true
Expand Down
73 changes: 73 additions & 0 deletions google/data_source_google_compute_regions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package google

import (
"fmt"
"log"
"sort"
"time"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"google.golang.org/api/compute/v1"
)

func dataSourceGoogleComputeRegions() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleComputeRegionsRead,
Schema: map[string]*schema.Schema{
"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"status": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"UP", "DOWN"}, false),
},
},
}
}

func dataSourceGoogleComputeRegionsRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
}
filter := ""
if s, ok := d.GetOk("status"); ok {
filter = fmt.Sprintf(" (status eq %s)", s)
}

call := config.clientCompute.Regions.List(project).Filter(filter)

resp, err := call.Do()
if err != nil {
return err
}

regions := flattenRegions(resp.Items)
log.Printf("[DEBUG] Received Google Compute Regions: %q", regions)

d.Set("names", regions)
d.Set("project", project)
d.SetId(time.Now().UTC().String())

return nil
}

func flattenRegions(regions []*compute.Region) []string {
result := make([]string, len(regions), len(regions))
for i, region := range regions {
result[i] = region.Name
}
sort.Strings(result)
return result
}
72 changes: 72 additions & 0 deletions google/data_source_google_compute_regions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package google

import (
"errors"
"fmt"
"strconv"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeRegions_basic(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleComputeRegionsConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleComputeRegionsMeta("data.google_compute_regions.available"),
),
},
},
})
}

func testAccCheckGoogleComputeRegionsMeta(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find regions data source: %s", n)
}

if rs.Primary.ID == "" {
return errors.New("regions data source ID not set.")
}

count, ok := rs.Primary.Attributes["names.#"]
if !ok {
return errors.New("can't find 'names' attribute")
}

noOfNames, err := strconv.Atoi(count)
if err != nil {
return errors.New("failed to read number of regions")
}
if noOfNames < 2 {
return fmt.Errorf("expected at least 2 regions, received %d, this is most likely a bug",
noOfNames)
}

for i := 0; i < noOfNames; i++ {
idx := "names." + strconv.Itoa(i)
v, ok := rs.Primary.Attributes[idx]
if !ok {
return fmt.Errorf("region list is corrupt (%q not found), this is definitely a bug", idx)
}
if len(v) < 1 {
return fmt.Errorf("Empty region name (%q), this is definitely a bug", idx)
}
}

return nil
}
}

var testAccCheckGoogleComputeRegionsConfig = `
data "google_compute_regions" "available" {}
`
128 changes: 128 additions & 0 deletions google/data_source_google_netblock_ip_ranges.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package google

import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"io/ioutil"
"net/http"
"strings"
)

func dataSourceGoogleNetblockIpRanges() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleNetblockIpRangesRead,

Schema: map[string]*schema.Schema{
"cidr_blocks": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"cidr_blocks_ipv4": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"cidr_blocks_ipv6": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
},
}
}

func dataSourceGoogleNetblockIpRangesRead(d *schema.ResourceData, meta interface{}) error {
d.SetId("netblock-ip-ranges")

// https://cloud.google.com/compute/docs/faq#where_can_i_find_product_name_short_ip_ranges
CidrBlocks, err := getCidrBlocks()

if err != nil {
return err
}

d.Set("cidr_blocks", CidrBlocks["cidr_blocks"])
d.Set("cidr_blocks_ipv4", CidrBlocks["cidr_blocks_ipv4"])
d.Set("cidr_blocks_ipv6", CidrBlocks["cidr_blocks_ipv6"])

return nil
}

func netblock_request(name string) (string, error) {
const DNS_URL = "https://dns.google.com/resolve?name=%s&type=TXT"

response, err := http.Get(fmt.Sprintf("https://dns.google.com/resolve?name=%s&type=TXT", name))

if err != nil {
return "", fmt.Errorf("Error from _cloud-netblocks: %s", err)
}

defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)

if err != nil {
return "", fmt.Errorf("Error to retrieve the domains list: %s", err)
}

return string(body), nil
}

func getCidrBlocks() (map[string][]string, error) {
const INITIAL_NETBLOCK_DNS = "_cloud-netblocks.googleusercontent.com"
var dnsNetblockList []string
cidrBlocks := make(map[string][]string)

response, err := netblock_request(INITIAL_NETBLOCK_DNS)

if err != nil {
return nil, err
}

splitedResponse := strings.Split(string(response), " ")

for _, sp := range splitedResponse {
if strings.HasPrefix(sp, "include:") {
dnsNetblock := strings.Replace(sp, "include:", "", 1)
dnsNetblockList = append(dnsNetblockList, dnsNetblock)
}
}

for len(dnsNetblockList) > 0 {

dnsNetblock := dnsNetblockList[0]

dnsNetblockList[0] = ""
dnsNetblockList = dnsNetblockList[1:len(dnsNetblockList)]

response, err = netblock_request(dnsNetblock)

if err != nil {
return nil, err
}

splitedResponse = strings.Split(string(response), " ")

for _, sp := range splitedResponse {
if strings.HasPrefix(sp, "ip") {

cdrBlock := strings.Split(sp, ":")[1]
cidrBlocks["cidr_blocks"] = append(cidrBlocks["cidr_blocks"], cdrBlock)

if strings.HasPrefix(sp, "ip4") {
cdrBlock := strings.Replace(sp, "ip4:", "", 1)
cidrBlocks["cidr_blocks_ipv4"] = append(cidrBlocks["cidr_blocks_ipv4"], cdrBlock)

} else if strings.HasPrefix(sp, "ip6") {
cdrBlock := strings.Replace(sp, "ip6:", "", 1)
cidrBlocks["cidr_blocks_ipv6"] = append(cidrBlocks["cidr_blocks_ipv6"], cdrBlock)
}
} else if strings.HasPrefix(sp, "include:") {
cidr_block := strings.Replace(sp, "include:", "", 1)
dnsNetblockList = append(dnsNetblockList, cidr_block)
}
}
}

return cidrBlocks, nil
}
38 changes: 38 additions & 0 deletions google/data_source_google_netblock_ip_ranges_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package google

import (
"regexp"
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceGoogleNetblockIpRanges_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetblockIpRangesConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.some",
"cidr_blocks.#", regexp.MustCompile(("^[1-9]+[0-9]*$"))),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.some",
"cidr_blocks.0", regexp.MustCompile("^[0-9./:]+$")),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.some",
"cidr_blocks_ipv4.#", regexp.MustCompile(("^[1-9]+[0-9]*$"))),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.some",
"cidr_blocks_ipv4.0", regexp.MustCompile("^[0-9./]+$")),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.some",
"cidr_blocks_ipv6.#", regexp.MustCompile(("^[1-9]+[0-9]*$"))),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.some",
"cidr_blocks_ipv6.0", regexp.MustCompile("^[0-9./:]+$")),
),
},
},
})
}

const testAccNetblockIpRangesConfig = `
data "google_netblock_ip_ranges" "some" {}
`
Loading

0 comments on commit a223776

Please sign in to comment.