Skip to content

Commit

Permalink
Terraform: Skip diffs when managed certs are specified with absolute …
Browse files Browse the repository at this point in the history
…FQDNs

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
drebes authored and modular-magician committed Apr 29, 2019
1 parent 0e19dec commit 6cfc80c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions google-beta/resource_compute_managed_ssl_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func resourceComputeManagedSslCertificate() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"domains": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Type: schema.TypeList,
Required: true,
ForceNew: true,
DiffSuppressFunc: absoluteDomainSuppress,
MaxItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "google_compute_managed_ssl_certificate" "default" {
name = "test-cert-%{random_suffix}"
managed {
domains = ["sslcert.tf-test.club"]
domains = ["sslcert.tf-test.club."]
}
}
Expand Down
8 changes: 8 additions & 0 deletions google-beta/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,11 @@ func paginatedListRequest(baseUrl string, config *Config, flattener func(map[str

return ls, nil
}

// For managed SSL certs, if new is an absolute FQDN (trailing '.') but old isn't, treat them as equals.
func absoluteDomainSuppress(k, old, new string, _ *schema.ResourceData) bool {
if k == "managed.0.domains.0" {
return old == strings.TrimRight(new, ".")
}
return old == new
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ resource "google_compute_managed_ssl_certificate" "default" {
name = "test-cert"
managed {
domains = ["sslcert.tf-test.club"]
domains = ["sslcert.tf-test.club."]
}
}
Expand Down

0 comments on commit 6cfc80c

Please sign in to comment.