Skip to content

Dynamic snippet breaks versioning #781

Open
@RmMsr

Description

@RmMsr

Terraform Version

Terraform v1.5.6
on linux_amd64
+ provider registry.terraform.io/fastly/fastly v5.4.0

Affected Fastly Terraform Resource(s)

  • fastly_service_vcl
  • fastly_service_dynamic_snippet_content

Terraform Configuration Files

resource "fastly_service_vcl" "test" {
  name = "test"

  dynamicsnippet {
    name = "status-503-error"
    type = "error"
  }
}

resource "fastly_service_dynamic_snippet_content" "test" {
  content    = "# Placeholder"
  service_id = "abc123"
  snippet_id = "abc123"
}

Expected Behavior

The dynamic snippet should not be part of the versioned VCL.

Actual Behavior

The existing already activated VCL version is altered and now contains the dynamic snippet. If the snippet is updated the VCL stays on the modified content. Is is not possible to know which snippet is actually running by then.

Besides this strongly contrasts the description of a dynamic snippet and promises of the VCL versioning.

Debug Output (optional)

Steps to Reproduce

Step 1 We initially add a dynamicsnippet block with a placeholder content. Same result is with empty content.

 ~ resource "fastly_service_vcl" "test" {
      ~ active_version     = 141 -> (known after apply)
      ~ cloned_version     = 141 -> (known after apply)
        id                 = "test"
        name               = "Test"
        # (9 unchanged attributes hidden)

      + dynamicsnippet {
          + name       = "status-503-error"
          + priority   = 100
          + snippet_id = (known after apply)
          + type       = "error"
        }

Results in new VCL version with this block:

# Snippet status-503-error : 100

This is expected.

Now we add a fastly_service_dictionary_items resource:

resource "fastly_service_dynamic_snippet_content" "status-page" {
  for_each = {
    for d in fastly_service_vcl.test.dynamicsnippet : d.name => d if startswith(d.name, "status-")
  }
  content    = <<-CONTENT
    if (obj.status == ${parseint(regex("status-(\\d{3}).*", each.key)[0], 10) + 400}) {
      set obj.status = ${regex("status-(\\d{3}).*", each.key)[0]};
      set obj.http.content-type = "text/html; charset=utf-8";
      synthetic {"${file("${path.module}/response/${regex("status-(\\d{3}).*", each.key)[0]}.html")}"};
      return(deliver);
    }
  CONTENT
  service_id = fastly_service_vcl.test.id
  snippet_id = each.value.snippet_id
  manage_snippets = true
}

Terraform tells:

  # fastly_service_dynamic_snippet_content.status-page["status-503-error"] will be created
  + resource "fastly_service_dynamic_snippet_content" "status-page" {
      + content         = <<-EOT
# ...
Plan: 1 to add, 0 to change, 0 to destroy.

Sounds good, but it changes the active VCL version in place and adds the content in place.

# Snippet status-503-error : 100
if (obj.status == 903) {
  set obj.status = 503;
  set obj.http.content-type = "text/html; charset=utf-8";
  synthetic {"<!doctype html>
# ...

The webinterface still claims this should be a dynamic snippet

Important Factoids (optional)

Initially I tried to only use the dynamicsnippet within fastly_service_vcl. But that kept detecting a change on every plan even without any change to the HCL. As it is simpler I would have preferred that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions