Skip to content

Commit ef8cbb1

Browse files
authored
[CDTOOL-1202] Correct 'TestAccResourceFastlyTLSSubscription_Config' Failure (#1135)
* apply check to update * changelog update
1 parent cb3c21f commit ef8cbb1

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- fix(backend): preserve optional bool fields (`use_ssl`, `ssl_check_cert`, `prefer_ipv6`, `auto_loadbalance`) during updates and add acceptance test coverage ([#1133](https://github.com/fastly/terraform-provider-fastly/pull/1133))
1515
- fix(domains_v1/service_link): corrected a behavior where new service links created were not referring to 'domain_id' values correctly ([#1132](https://github.com/fastly/terraform-provider-fastly/pull/1132))
1616
- fix(logging/compute): corrected drift behavior for some compute logging endpoints where the value of 'period' was not being retained correctly ([#1134](https://github.com/fastly/terraform-provider-fastly/pull/1134))
17+
- fix(tls/subscriptions): corrects 'common_name' validation for update operations ([#1135](https://github.com/fastly/terraform-provider-fastly/pull/1135))
1718

1819
### DEPENDENCIES:
1920

fastly/resource_fastly_tls_subscription.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,22 @@ func resourceFastlyTLSSubscriptionUpdate(ctx context.Context, d *schema.Resource
370370
// field on the input struct if there was a change because we otherwise
371371
// can't guarantee the order.
372372
var domains []*gofastly.TLSDomain
373+
var domainStrings []string
373374
for _, domain := range d.Get("domains").(*schema.Set).List() {
374375
domains = append(domains, &gofastly.TLSDomain{ID: domain.(string)})
376+
domainStrings = append(domainStrings, domain.(string))
377+
}
378+
379+
// Validate that common_name is in domains
380+
commonNameStr := d.Get("common_name").(string)
381+
if commonNameStr != "" && !contains(domainStrings, commonNameStr) {
382+
return diag.Errorf("domain specified as common_name (%s) must also be in domains (%v)", commonNameStr, domainStrings)
375383
}
376384

377385
updates := &gofastly.UpdateTLSSubscriptionInput{
378386
ID: d.Id(),
379387
Force: d.Get("force_update").(bool),
380-
CommonName: &gofastly.TLSDomain{ID: d.Get("common_name").(string)},
388+
CommonName: &gofastly.TLSDomain{ID: commonNameStr},
381389
Domains: domains,
382390

383391
// IMPORTANT: We should always pass the configuration_id to the API.

fastly/resource_fastly_tls_subscription_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestAccResourceFastlyTLSSubscription_Config(t *testing.T) {
6767
},
6868
{
6969
Config: testAccResourceFastlyTLSSubscriptionConfigInvalidCommonName(),
70-
ExpectError: regexp.MustCompile(`Please add \S+ to an active service to begin TLS enablement`),
70+
ExpectError: regexp.MustCompile(`domain specified as common_name .* must also be in domains`),
7171
},
7272
{
7373
Config: testAccResourceFastlyTLSSubscriptionConfig(name, domain1, domain2Bad, commonName2),

0 commit comments

Comments
 (0)