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

Correctly update version_comment #466

Merged
merged 1 commit into from
Sep 2, 2021
Merged
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
4 changes: 2 additions & 2 deletions fastly/base_fastly_service_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta int
}

// Update the cloned version's comment. No new version is required for this.
if d.HasChange("version_comment") && !needsChange {
if d.HasChange("version_comment") && (!needsChange || isCreate) {
opts := gofastly.UpdateVersionInput{
ServiceID: d.Id(),
ServiceVersion: d.Get("cloned_version").(int),
Expand Down Expand Up @@ -526,7 +526,7 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter
if err != nil {
return diag.FromErr(err)
}
err = d.Set("version_comment", s.Version.Comment)
err = d.Set("version_comment", s.ActiveVersion.Comment)
if err != nil {
return diag.FromErr(err)
}
Expand Down
31 changes: 26 additions & 5 deletions fastly/resource_fastly_service_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ func TestAccFastlyServiceV1_basic(t *testing.T) {
var service gofastly.ServiceDetail
name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
comment := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
versionComment := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
versionComment1 := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
versionComment2 := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
domainName1 := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))
domainName2 := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))

Expand All @@ -414,15 +415,15 @@ func TestAccFastlyServiceV1_basic(t *testing.T) {
CheckDestroy: testAccCheckServiceV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccServiceV1Config(name, domainName1),
Config: testAccServiceV1Config_initWithVerstionComment(name, versionComment1, domainName1),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceV1Exists("fastly_service_v1.foo", &service),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "name", name),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "comment", "Managed by Terraform"),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "version_comment", ""),
"fastly_service_v1.foo", "version_comment", versionComment1),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "active_version", "1"),
resource.TestCheckResourceAttr(
Expand All @@ -432,15 +433,15 @@ func TestAccFastlyServiceV1_basic(t *testing.T) {
),
},
{
Config: testAccServiceV1Config_basicUpdate(name, comment, versionComment, domainName2),
Config: testAccServiceV1Config_basicUpdate(name, comment, versionComment2, domainName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceV1Exists("fastly_service_v1.foo", &service),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "name", name),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "comment", comment),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "version_comment", versionComment),
"fastly_service_v1.foo", "version_comment", versionComment2),
resource.TestCheckResourceAttr(
"fastly_service_v1.foo", "active_version", "2"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -765,6 +766,26 @@ resource "fastly_service_v1" "foo" {
}`, name, domain)
}

func testAccServiceV1Config_initWithVerstionComment(name, versionComment, domain string) string {
return fmt.Sprintf(`
resource "fastly_service_v1" "foo" {
name = "%s"
version_comment = "%s"

domain {
name = "%s"
comment = "tf-testing-domain"
}

backend {
address = "aws.amazon.com"
name = "amazon docs"
}

force_destroy = true
}`, name, versionComment, domain)
}

func testAccServiceV1Config_default_host(name, domain, defaultHost string) string {
return fmt.Sprintf(`
resource "fastly_service_v1" "foo" {
Expand Down