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

Changing the env key recreates flags in all other envs as well. #143

Open
mohamaa opened this issue Apr 17, 2023 · 3 comments
Open

Changing the env key recreates flags in all other envs as well. #143

mohamaa opened this issue Apr 17, 2023 · 3 comments

Comments

@mohamaa
Copy link

mohamaa commented Apr 17, 2023

Is there a way to ignore the recreation of flags in other envs?

I am trying launchdarkly_feature_flag_environment which maintains env-specific flag configurations.
I want to manage each envs targets differently but when I change the env it recreates the flags in other envs as well.
I am trying Lifecycle but it has no effects.

resource "launchdarkly_feature_flag_environment" "mohamaa-featurex_env" {
for_each = { for i, v in var.ff_list : i => v }
flag_id = launchdarkly_feature_flag.mohamaa-featurex[each.key].id #.id
env_key = data.launchdarkly_[environment.dev](http://environment.dev/).key
on = each.value.targeting_enabled
targets {
values = each.value.targets #["missing-user"]
variation = 0
}
fallthrough {
variation = 0
}
off_variation = 1
lifecycle {
ignore_changes = [
# Ignore changes to tags, e.g. because a management agent
# updates these based on some ruleset managed elsewhere.
fallthrough,
targets,
flag_id
]
}
}
@ldhenry
Copy link
Collaborator

ldhenry commented Apr 19, 2023

Hey @mohamaa, I'm not sure if I fully understand the problem here but I think there might be something going on with the for loops you are using. I tried to reproduce with a simplified example and did not encounter any issues. Here is the config I was using:

variable "ff_list" {
  type    = list(string)
  default = ["flag1", "flag2"]
}

resource "launchdarkly_feature_flag" "list_flags" {
  for_each       = toset(var.ff_list)
  project_key    = "projectx"
  key            = each.key
  name           = each.key
  variation_type = "boolean"
}

resource "launchdarkly_feature_flag_environment" "test_env" {
  for_each = toset(var.ff_list)
  flag_id  = launchdarkly_feature_flag.list_flags[each.key].id
  env_key  = "production" # Changing this to "test" and reapplying does not cause the issue you are describing

  fallthrough {
    variation = 0
  }
  off_variation = 1
  on            = true
}

To help us get to the bottom of this would you mind sharing what your var.ff_list looks like?

@mohamaa
Copy link
Author

mohamaa commented May 1, 2023

Here is my variables.tf

variable "ff_list1" {
  description = "An object that contains all the ff list and its persona/targets"
  type = list(object({
    ff_name           = string
    targeting_enabled = string
    targets           = list(string)
  }))
  default = [
    {
      ff_name           = "mohamaa-april24",
      targeting_enabled = "true"
      targets           = ["foo-bar"]
    }
  ]
}

@sloloris
Copy link
Contributor

Hi @mohamaa,

Can you clarify what you mean by 'recreating the flags in other environments'? Do you mean it overwrites the targeting rules in other environments? If so, I concur with my colleague - something about the way you are looping may be causing the issue.

I was not able to produce any strange or unexpected behavior from these configurations, but if you are still encountering this issue, please describe it in more detail so we can better work at reproducing your problem, including complete configurations if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants