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

Added service_directory_registrations to forwarding_rule resource #5936

Closed
wants to merge 13 commits into from
Closed
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
3 changes: 2 additions & 1 deletion mmv1/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ DEPENDENCIES

BUNDLED WITH
1.17.2



20 changes: 20 additions & 0 deletions mmv1/products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,26 @@ objects:
- :PREMIUM
- :STANDARD
input: true
- !ruby/object:Api::Type::Array
name: 'serviceDirectoryRegistrations'
description: |
Service Directory resources to register this forwarding rule with. Currently,
only supports a single Service Directory resource.
required: false
min_size: 0
max_size: 1
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'namespace'
description: |
Service Directory namespace to register the forwarding rule under.
required: true
- !ruby/object:Api::Type::String
name: 'service'
description: |
Service Directory service to register the forwarding rule under.
required: true
- !ruby/object:Api::Type::String
name: 'serviceLabel'
description: |
Expand Down
2 changes: 1 addition & 1 deletion mmv1/third_party/terraform/go.mod.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module github.com/hashicorp/terraform-provider-google<%= "-" + version unless ve
require (
cloud.google.com/go/bigtable v1.13.0
cloud.google.com/go/iam v0.1.1 // indirect
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.1.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.4.1
github.com/apparentlymart/go-cidr v1.1.0
github.com/client9/misspell v0.3.4
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 4 additions & 0 deletions mmv1/third_party/terraform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1543,3 +1543,7 @@ github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-202203
github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20220316014534-ac1c1c4fdb29/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.1.0 h1:6EDY4EUsCW/mTRzYJ8SEzL2V5JACYCiIswnbhpaAwaY=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.1.0/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.2.0 h1:9QuwqVrdqoNyOgLkIsrh+liBphawCZIfZJgsLIVWkts=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.2.0/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.4.1 h1:nqlJvanh1GLSkVNpw6e4ecXtMd8Vl7c/USkI9qTyVzI=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.4.1/go.mod h1:UJoDYx6t3+xCOd+dZX8+NrEB+Y/eW1pQlvxh2Gt7y5E=
Original file line number Diff line number Diff line change
Expand Up @@ -2,127 +2,195 @@
package google

import (
"fmt"
"testing"
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

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

poolName := fmt.Sprintf("tf-%s", randString(t, 10))
ruleName := fmt.Sprintf("tf-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeForwardingRule_basic(poolName, ruleName),
},
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
resource.TestStep{
Config: testAccComputeForwardingRule_update(poolName, ruleName),
},
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
t.Parallel()

poolName := fmt.Sprintf("tf%s", randString(t, 10))
ruleName := fmt.Sprintf("tf%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_basic(poolName, ruleName),
},
{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeForwardingRule_update(poolName, ruleName),
},
{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}


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

addrName := fmt.Sprintf("tf-%s", randString(t, 10))
poolName := fmt.Sprintf("tf-%s", randString(t, 10))
ruleName := fmt.Sprintf("tf-%s", randString(t, 10))
addressRefFieldRaw := "address"
addressRefFieldID := "id"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeForwardingRule_ip(addrName, poolName, ruleName, addressRefFieldID),
},
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ip_address"}, // ignore ip_address because we've specified it by ID
},
resource.TestStep{
Config: testAccComputeForwardingRule_ip(addrName, poolName, ruleName, addressRefFieldRaw),
},
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
t.Parallel()

addrName := fmt.Sprintf("tf-%s", randString(t, 10))
poolName := fmt.Sprintf("tf-%s", randString(t, 10))
ruleName := fmt.Sprintf("tf-%s", randString(t, 10))
addressRefFieldRaw := "address"
addressRefFieldID := "id"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeForwardingRule_ip(addrName, poolName, ruleName, addressRefFieldID),
},
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ip_address"}, // ignore ip_address because we've specified it by ID
},
resource.TestStep{
Config: testAccComputeForwardingRule_ip(addrName, poolName, ruleName, addressRefFieldRaw),
},
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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

poolName := fmt.Sprintf("tf-%s", randString(t, 10))
ruleName := fmt.Sprintf("tf-%s", randString(t, 10))
poolName := fmt.Sprintf("tf-%s", randString(t, 10))
ruleName := fmt.Sprintf("tf-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeForwardingRule_networkTier(poolName, ruleName),
},
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeForwardingRule_networkTier(poolName, ruleName),
},

resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
resource.TestStep{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
return fmt.Sprintf(`
resource "google_compute_target_pool" "foo-tp" {
description = "Resource created for Terraform acceptance testing"
instances = ["us-central1-a/foo", "us-central1-b/bar"]
name = "foo-%s"
func TestAccComputeForwardingRule_serviceDirectoryRegistrations(t *testing.T) {
t.Parallel()

poolName := fmt.Sprintf("tf%s", randString(t, 10))
ruleName := fmt.Sprintf("tf%s", randString(t, 10))
svcDirNamespace := fmt.Sprintf("svcdirns-%s", randString(t, 10))
serviceName := fmt.Sprintf("svcdirservice-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_serviceDirectoryRegistrations(poolName, ruleName, svcDirNamespace, serviceName),
},
{
ResourceName: "google_compute_forwarding_rule.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

resource "google_compute_forwarding_rule" "foobar" {
description = "Resource created for Terraform acceptance testing"
ip_protocol = "UDP"
name = "%s"
port_range = "80-81"
target = google_compute_target_pool.foo-tp.self_link
<% unless version == 'ga' -%>
labels = {
"foo" = "bar"
func testAccComputeForwardingRule_serviceDirectoryRegistrations(poolName, ruleName, svcDirNamespace, serviceName string) string {
return fmt.Sprintf(`
resource "google_compute_target_pool" "foo-tp" {
description = "Resource created for Terraform acceptance testing"
instances = ["us-central1-a/foo", "us-central1-b/bar"]
name = "foo-%s"
}
<% end -%>
}
`, poolName, ruleName)

resource "google_compute_forwarding_rule" "foobar" {
description = "Resource created for Terraform acceptance testing"
ip_protocol = "UDP"
name = "%s"
port_range = "80-81"
target = google_compute_target_pool.foo-tp.self_link

service_directory_registrations {
namespace = google_service_directory_namespace.examplens.namespace_id
service = google_service_directory_service.examplesvc.service_id
}
}

resource "google_service_directory_namespace" "examplens" {
namespace_id = "%s"
location = "us-central1"
}

resource "google_service_directory_service" "examplesvc" {
service_id = "%s"
namespace = google_service_directory_namespace.examplens.id

metadata = {
stage = "prod"
region = "us-central1"
}
}

`, poolName, ruleName, svcDirNamespace, serviceName)
}

func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
return fmt.Sprintf(`
resource "google_compute_target_pool" "foo-tp" {
description = "Resource created for Terraform acceptance testing"
instances = ["us-central1-a/foo", "us-central1-b/bar"]
name = "foo-%s"
}

resource "google_compute_forwarding_rule" "foobar" {
description = "Resource created for Terraform acceptance testing"
ip_protocol = "UDP"
name = "%s"
port_range = "80-81"
target = google_compute_target_pool.foo-tp.self_link

<% unless version == 'ga' %>
labels = {
"foo" = "bar"
}
<% end %>

}
`, poolName, ruleName)
}


func testAccComputeForwardingRule_update(poolName, ruleName string) string {
return fmt.Sprintf(`
return fmt.Sprintf(`
resource "google_compute_target_pool" "foo-tp" {
description = "Resource created for Terraform acceptance testing"
instances = ["us-central1-a/foo", "us-central1-b/bar"]
Expand All @@ -141,17 +209,19 @@ resource "google_compute_forwarding_rule" "foobar" {
name = "%s"
port_range = "80-81"
target = google_compute_target_pool.bar-tp.self_link
<% unless version == 'ga' -%>
labels = {
"baz" = "qux"
}
<% end -%>

<% unless version == 'ga' %>
labels = {
baz = "qux"
}
<% end %>
}

`, poolName, poolName, ruleName)
}

func testAccComputeForwardingRule_ip(addrName, poolName, ruleName, addressRefFieldValue string) string {
return fmt.Sprintf(`
return fmt.Sprintf(`
resource "google_compute_address" "foo" {
name = "%s"
}
Expand All @@ -174,7 +244,7 @@ resource "google_compute_forwarding_rule" "foobar" {
}

func testAccComputeForwardingRule_networkTier(poolName, ruleName string) string {
return fmt.Sprintf(`
return fmt.Sprintf(`
resource "google_compute_target_pool" "foobar-tp" {
description = "Resource created for Terraform acceptance testing"
instances = ["us-central1-a/foo", "us-central1-b/bar"]
Expand Down
2 changes: 1 addition & 1 deletion tpgtools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
bitbucket.org/creachadair/stringset v0.0.9
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.1.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.4.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/hcl v1.0.0
Expand Down
Loading