Skip to content

Errors when making changes to a Gate with the V2 Provider #8

@alexeiser

Description

@alexeiser

The sample gate from https://registry.terraform.io/providers/statsig-io/statsig/latest/docs/resources/gate can not be modified with out an error unless the ID field is set.

e.g. terraform:

resource "statsig_gate" "simple" {
  name        = "simple_gate"
  id        = "simple_gate"
  description = "A short description of what Another Gate is used for."
  is_enabled  = false
  id_type     = "userID"
  rules = [
    {
      name            = "All Conditions"
      pass_percentage = 10
      conditions = [
        {
          type = "public"
        }
      ]
    }
  ]
}

Then apply the terraform:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # statsig_gate.simple will be created
  + resource "statsig_gate" "simple" {
      + creator_email        = (known after apply)
      + creator_id           = (known after apply)
      + description          = "A short description of what Another Gate is used for."
      + id                   = (known after apply)
      + id_type              = "userID"
      + is_enabled           = false
      + measure_metric_lifts = (known after apply)
      + monitoring_metrics   = (known after apply)
      + name                 = "simple_gate"
      + rules                = [
          + {
              + base_id         = (known after apply)
              + conditions      = [
                  + {
                      + custom_id    = (known after apply)
                      + field        = (known after apply)
                      + operator     = (known after apply)
                      + target_value = []
                      + type         = "public"
                    },
                ]
              + environments    = []
              + id              = (known after apply)
              + name            = "All Conditions"
              + pass_percentage = 10
              + return_value    = (known after apply)
            },
        ]
      + tags                 = (known after apply)
      + target_apps          = (known after apply)
      + team                 = (known after apply)
      + type                 = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

statsig_gate.simple: Creating...
statsig_gate.simple: Creation complete after 1s [id=simple_gate]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

kaja-tf/statsig/enterprise on  main [$!?] via 💠 default on ☁️  (us-west-2) took 3s 

Pass Percentage is chanted to 20%


❯ terraform apply --var-file dev.tfvars
statsig_gate.simple: Refreshing state... [id=simple_gate]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # statsig_gate.simple will be updated in-place
  ~ resource "statsig_gate" "simple" {
      + creator_email        = (known after apply)
      ~ creator_id           = "3lDYlY5OsFLmbZLBWCpAXC" -> (known after apply)
      ~ id                   = "simple_gate" -> (known after apply)
      ~ measure_metric_lifts = true -> (known after apply)
      ~ monitoring_metrics   = [
          - {
              - name = "dau" -> null
              - type = "user" -> null
            },
          - {
              - name = "mau_28d" -> null
              - type = "user" -> null
            },
          - {
              - name = "new_dau" -> null
              - type = "user" -> null
            },
          - {
              - name = "l7" -> null
              - type = "user" -> null
            },
          - {
              - name = "wau" -> null
              - type = "user" -> null
            },
          - {
              - name = "weekly_stickiness" -> null
              - type = "user" -> null
            },
          - {
              - name = "monthly_stickiness" -> null
              - type = "user" -> null
            },
        ] -> (known after apply)
        name                 = "simple_gate"
      ~ rules                = [
          ~ {
              ~ base_id         = "7kUAWX2HIsITEvEgwR3B82" -> (known after apply)
              ~ conditions      = [
                  ~ {
                      + custom_id    = (known after apply)
                      + field        = (known after apply)
                      + operator     = (known after apply)
                        # (2 unchanged attributes hidden)
                    },
                ]
              ~ id              = "7kUAWX2HIsITEvEgwR3B82" -> (known after apply)
                name            = "All Conditions"
              ~ pass_percentage = 10 -> 20
              + return_value    = (known after apply)
                # (1 unchanged attribute hidden)
            },
        ]
      ~ tags                 = [] -> (known after apply)
      ~ target_apps          = [] -> (known after apply)
      + team                 = (known after apply)
      ~ type                 = "TEMPORARY" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

statsig_gate.simple: Modifying... [id=simple_gate]
╷
│ Error: Internal API Error
│ 
│   with statsig_gate.simple,
│   on gate_portal.tf line 41, in resource "statsig_gate" "simple":
│   41: resource "statsig_gate" "simple" {
│ 
│ While calling the API, an unexpected error occurred. Please contact support if you are unsure how to resolve the error.
│ 
│ Error: Failed PATCH request to https://api.statsig.com/console/v1/gates/ with status code 404.
╵

Throws an error: │ Error: Failed PATCH request to https://api.statsig.com/console/v1/gates/ with status code 404.

Add a static ID:

kaja-tf/statsig/enterprise on  main [$!?] via 💠 default on ☁️  (us-west-2) took 8s 
❯ terraform apply --var-file dev.tfvars
statsig_gate.simple: Refreshing state... [id=simple_gate]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # statsig_gate.simple will be updated in-place
  ~ resource "statsig_gate" "simple" {
      + creator_email        = (known after apply)
      ~ creator_id           = "3lDYlY5OsFLmbZLBWCpAXC" -> (known after apply)
        id                   = "simple_gate"
      ~ measure_metric_lifts = true -> (known after apply)
      ~ monitoring_metrics   = [
          - {
              - name = "dau" -> null
              - type = "user" -> null
            },
          - {
              - name = "mau_28d" -> null
              - type = "user" -> null
            },
          - {
              - name = "new_dau" -> null
              - type = "user" -> null
            },
          - {
              - name = "l7" -> null
              - type = "user" -> null
            },
          - {
              - name = "wau" -> null
              - type = "user" -> null
            },
          - {
              - name = "weekly_stickiness" -> null
              - type = "user" -> null
            },
          - {
              - name = "monthly_stickiness" -> null
              - type = "user" -> null
            },
        ] -> (known after apply)
        name                 = "simple_gate"
      ~ rules                = [
          ~ {
              ~ base_id         = "7kUAWX2HIsITEvEgwR3B82" -> (known after apply)
              ~ conditions      = [
                  ~ {
                      + custom_id    = (known after apply)
                      + field        = (known after apply)
                      + operator     = (known after apply)
                        # (2 unchanged attributes hidden)
                    },
                ]
              ~ id              = "7kUAWX2HIsITEvEgwR3B82" -> (known after apply)
                name            = "All Conditions"
              ~ pass_percentage = 10 -> 20
              + return_value    = (known after apply)
                # (1 unchanged attribute hidden)
            },
        ]
      ~ tags                 = [] -> (known after apply)
      ~ target_apps          = [] -> (known after apply)
      + team                 = (known after apply)
      ~ type                 = "TEMPORARY" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

statsig_gate.simple: Modifying... [id=simple_gate]
statsig_gate.simple: Modifications complete after 2s [id=simple_gate]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

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