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 new resource google_compute_target_ssl_proxy #569

Merged
merged 5 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 8 additions & 7 deletions google/resource_compute_target_ssl_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceComputeTargetSslProxyCreate(d *schema.ResourceData, meta interface{
return err
}

sslCertificates, err := expandSslCertificates(d.Get("ssl_certificates").([]interface{}), d, config)
sslCertificates, err := expandSslCertificates(d, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -121,12 +121,12 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{
d.Partial(true)

if d.HasChange("proxy_header") {
proxy_header := d.Get("proxy_header").(string)
proxy_header_payload := &compute.TargetSslProxiesSetProxyHeaderRequest{
ProxyHeader: proxy_header,
proxyHeader := d.Get("proxy_header").(string)
proxyHeaderPayload := &compute.TargetSslProxiesSetProxyHeaderRequest{
ProxyHeader: proxyHeader,
}
op, err := config.clientCompute.TargetSslProxies.SetProxyHeader(
project, d.Id(), proxy_header_payload).Do()
project, d.Id(), proxyHeaderPayload).Do()
if err != nil {
return fmt.Errorf("Error updating proxy_header: %s", err)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{
}

if d.HasChange("ssl_certificates") {
sslCertificates, err := expandSslCertificates(d.Get("ssl_certificates").([]interface{}), d, config)
sslCertificates, err := expandSslCertificates(d, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -231,7 +231,8 @@ func resourceComputeTargetSslProxyDelete(d *schema.ResourceData, meta interface{
return nil
}

func expandSslCertificates(configured []interface{}, d *schema.ResourceData, config *Config) ([]string, error) {
func expandSslCertificates(d *schema.ResourceData, config *Config) ([]string, error) {
configured := d.Get("ssl_certificates").([]interface{})
certs := make([]string, 0, len(configured))

for _, sslCertificate := range configured {
Expand Down
28 changes: 21 additions & 7 deletions google/resource_compute_target_ssl_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"reflect"
)

func TestAccComputeTargetSslProxy_basic(t *testing.T) {
Expand All @@ -23,8 +24,8 @@ func TestAccComputeTargetSslProxy_basic(t *testing.T) {
resource.TestStep{
Config: testAccComputeTargetSslProxy_basic1(target, cert, backend, hc),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetSslProxyExists(
"google_compute_target_ssl_proxy.foobar"),
testAccCheckComputeTargetSslProxy(
"google_compute_target_ssl_proxy.foobar", "NONE", []string{cert}),
),
},
},
Expand All @@ -47,15 +48,15 @@ func TestAccComputeTargetSslProxy_update(t *testing.T) {
resource.TestStep{
Config: testAccComputeTargetSslProxy_basic1(target, cert1, backend1, hc),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetSslProxyExists(
"google_compute_target_ssl_proxy.foobar"),
testAccCheckComputeTargetSslProxy(
"google_compute_target_ssl_proxy.foobar", "NONE", []string{cert1}),
),
},
resource.TestStep{
Config: testAccComputeTargetSslProxy_basic2(target, cert1, cert2, backend1, backend2, hc),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetSslProxyExists(
"google_compute_target_ssl_proxy.foobar"),
testAccCheckComputeTargetSslProxy(
"google_compute_target_ssl_proxy.foobar", "PROXY_V1", []string{cert1, cert2}),
),
},
},
Expand All @@ -80,7 +81,7 @@ func testAccCheckComputeTargetSslProxyDestroy(s *terraform.State) error {
return nil
}

func testAccCheckComputeTargetSslProxyExists(n string) resource.TestCheckFunc {
func testAccCheckComputeTargetSslProxy(n, proxyHeader string, sslCerts []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand All @@ -103,6 +104,19 @@ func testAccCheckComputeTargetSslProxyExists(n string) resource.TestCheckFunc {
return fmt.Errorf("TargetSslProxy not found")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to do more testing here (e.g. that the stored parameters match the set parameters)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if found.ProxyHeader != proxyHeader {
return fmt.Errorf("Wrong proxy header. Expected '%s', got '%s'", proxyHeader, found.ProxyHeader)
}

foundCertsName := make([]string, 0, len(found.SslCertificates))
for _, foundCert := range found.SslCertificates {
foundCertsName = append(foundCertsName, GetResourceNameFromSelfLink(foundCert))
}

if !reflect.DeepEqual(foundCertsName, sslCerts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does order matter? If it doesn't, you might consider sorting or something before doing the deepEqual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, after waiting for the full test run to finish and reading the API docs, one and only one certificate must be specified at this time (they might support more in the future). So I added a MaxItems:1 on the schema for now and simplified this check.

From the docs:
"Currently exactly one SslCertificate resource must be specified."

return fmt.Errorf("Wrong ssl certificates. Expected '%s', got '%s'", sslCerts, found.SslCertificates)
}

return nil
}
}
Expand Down