From bcf25503c4e3cfdfe1290bfc10376396fd5b68a9 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Tue, 18 Sep 2018 12:51:19 -0700 Subject: [PATCH 1/3] Support IP Range Reservation for Global Address. --- products/compute/api.yaml | 45 +++++++++++++++++++ products/compute/terraform.yaml | 4 ++ .../resource_compute_global_address_test.go | 36 +++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 965a0ba06647..9481ee180ad8 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -1088,6 +1088,51 @@ objects: description: | A reference to the region where the regional address resides. output: true + - !ruby/object:Api::Type::Integer + name: 'prefixLength' + description: | + The prefix length of the IP range. If not present, it means the + address field is a single IP address. + + This field is not applicable to addresses with addressType=EXTERNAL. + min_version: beta + - !ruby/object:Api::Type::Enum + name: 'addressType' + description: | + The type of the address to reserve, default is EXTERNAL. + + * EXTERNAL indicates public/external single IP address. + * INTERNAL indicates internal IP ranges belonging to some network. + values: + - :EXTERNAL + - :INTERNAL + default_value: :EXTERNAL + min_version: beta + - !ruby/object:Api::Type::Enum + name: 'purpose' + description: | + The purpose of the resource. For global internal addresses it can be + + * VPC_PEERING - for peer networks + + For regional internal addresses, it can be + + * GCE_ENDPOINT - VM internal IP, VM alias IP, Internal LB service IP. + + This field is not applicable to external addresses. + values: + - :VPC_PEERING + - :GCE_ENDPOINT + min_version: beta + - !ruby/object:Api::Type::String + name: 'network' + description: | + The URL of the network in which to reserve the IP range. The IP range + must be in RFC1918 space. The network cannot be deleted if there are + any reserved IP ranges referring to it. + + This can only be specified for a global internal address. + min_version: beta # status is not useful for state convergence # users[] is not useful for state convergence - !ruby/object:Api::Resource diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 0cbbd95ede35..3e68c913fbbd 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -348,6 +348,10 @@ overrides: !ruby/object:Provider::ResourceOverrides exclude: false region: !ruby/object:Provider::Terraform::PropertyOverride exclude: true + addressType: !ruby/object:Provider::Terraform::PropertyOverride + diff_suppress_func: 'emptyOrDefaultStringSuppress("EXTERNAL")' + network: !ruby/object:Provider::Terraform::PropertyOverride + diff_suppress_func: 'compareSelfLinkOrResourceName' custom_code: !ruby/object:Provider::Terraform::CustomCode post_create: templates/terraform/post_create/labels.erb GlobalForwardingRule: !ruby/object:Provider::Terraform::ResourceOverride diff --git a/templates/terraform/tests/resource_compute_global_address_test.go b/templates/terraform/tests/resource_compute_global_address_test.go index c93d724c3cac..7d78c2ce633e 100644 --- a/templates/terraform/tests/resource_compute_global_address_test.go +++ b/templates/terraform/tests/resource_compute_global_address_test.go @@ -67,6 +67,26 @@ func TestAccComputeGlobalAddress_ipv6(t *testing.T) { }) } +func TestAccComputeGlobalAddress_internal(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeGlobalAddressDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeGlobalAddress_internal(), + }, + resource.TestStep{ + ResourceName: "google_compute_global_address.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) @@ -156,3 +176,19 @@ resource "google_compute_global_address" "foobar" { ip_version = "IPV6" }`, acctest.RandString(10)) } + +func testAccComputeGlobalAddress_internal() string { + return fmt.Sprintf(` +resource "google_compute_network" "foobar" { + name = "address-test-%s" +} + + +resource "google_compute_global_address" "foobar" { + name = "address-test-%s" + address_type = "INTERNAL" + purpose = "VPC_PEERING" + prefix_length = 24 + network = "${google_compute_network.foobar.self_link}" +}`, acctest.RandString(10), acctest.RandString(10)) +} From 6427b03775f27eea18219276a4d55fec6c32b5a6 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 20 Sep 2018 09:33:32 -0700 Subject: [PATCH 2/3] including DNS_RESOlVER as valid purpose --- products/compute/api.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 9481ee180ad8..3a87e4aeb1f1 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -1120,9 +1120,12 @@ objects: * GCE_ENDPOINT - VM internal IP, VM alias IP, Internal LB service IP. This field is not applicable to external addresses. + + * DNS_RESOLVER - Used for DNS forwarding values: - :VPC_PEERING - :GCE_ENDPOINT + - :DNS_RESOLVER min_version: beta - !ruby/object:Api::Type::String name: 'network' From 99f4a037fdeedefdb8af0f645ddbaeabc9e8db2f Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 20 Sep 2018 16:32:00 -0700 Subject: [PATCH 3/3] applying code review feedback --- products/compute/api.yaml | 16 +++++----------- products/compute/terraform.yaml | 2 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 3a87e4aeb1f1..5ca0b17e0029 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -1114,27 +1114,21 @@ objects: The purpose of the resource. For global internal addresses it can be * VPC_PEERING - for peer networks - - For regional internal addresses, it can be - - * GCE_ENDPOINT - VM internal IP, VM alias IP, Internal LB service IP. - - This field is not applicable to external addresses. - * DNS_RESOLVER - Used for DNS forwarding + This should only be set when using an Internal address. values: - :VPC_PEERING - - :GCE_ENDPOINT - - :DNS_RESOLVER min_version: beta - - !ruby/object:Api::Type::String + - !ruby/object:Api::Type::ResourceRef name: 'network' + resource: 'Network' + imports: 'selfLink' description: | The URL of the network in which to reserve the IP range. The IP range must be in RFC1918 space. The network cannot be deleted if there are any reserved IP ranges referring to it. - This can only be specified for a global internal address. + This should only be set when using an Internal address. min_version: beta # status is not useful for state convergence # users[] is not useful for state convergence diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 3e68c913fbbd..04d08f88a296 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -350,8 +350,6 @@ overrides: !ruby/object:Provider::ResourceOverrides exclude: true addressType: !ruby/object:Provider::Terraform::PropertyOverride diff_suppress_func: 'emptyOrDefaultStringSuppress("EXTERNAL")' - network: !ruby/object:Provider::Terraform::PropertyOverride - diff_suppress_func: 'compareSelfLinkOrResourceName' custom_code: !ruby/object:Provider::Terraform::CustomCode post_create: templates/terraform/post_create/labels.erb GlobalForwardingRule: !ruby/object:Provider::Terraform::ResourceOverride