netlify / terraform-provider-netlify

MIT License
2 stars 2 forks source link

Issue setting environment variable for branch context #48

Closed SalehAly01 closed 3 months ago

SalehAly01 commented 3 months ago

Hello,

We are using netlify_environment_variable to set some env variables on the team level, and it works fine if we use set context to all or we use one of the predefined contexts ["production", "branch-deploy", "deploy-preview", "dev"]. But if we try to set context to branch and provide the branch name as context_parameter, it fails due to a validation error.

I am sharing below an example of the code and the error.

resource "netlify_environment_variable" "password_context" {
  team_id = data.netlify_team.company.id
  key     = "PASSWORD_CONTEXT"
  values = [
    {
      value             = "staging"
      context           = "branch"
      context_parameter = "staging"
    },
    {
      value             = "onboarding"
      context           = "branch"
      context_parameter = "onboarding"
    },
    {
      value   = "production"
      context = "production"
    },
    {
      value   = "branch-deploy"
      context = "branch-deploy"
    },
    {
      value   = "deploy-preview"
      context = "deploy-preview"
    }
  ]
}

And this is the resulting error:

│ Error: Invalid Attribute Combination
│ 
│   with netlify_environment_variable.password_context,
│   on main.tf line 190, in resource "netlify_environment_variable" "password_context":
│  190:   values = [
│  191:     {
│  192:       value             = "staging"
│  193:       context           = "branch"
│  194:       context_parameter = "staging"
│  195:     },
│  196:     {
│  197:       value             = "onboarding"
│  198:       context           = "branch"
│  199:       context_parameter = "onboarding"
│  200:     },
│  201:     {
│  202:       value   = "production"
│  203:       context = "production"
│  204:     },
│  205:     {
│  206:       value   = "branch-deploy"
│  207:       context = "branch-deploy"
│  208:     },
│  209:     {
│  210:       value   = "deploy-preview"
│  211:       context = "deploy-preview"
│  212:     }
│  213:   ]
│ 
│ Attribute "values[Value({\"context\":\"branch\",\"context_parameter\":\"onboarding\",\"value\":\"onboarding\"})].context_parameter" must be a non-empty string iff
│ "values[Value({\"context\":\"branch\",\"context_parameter\":\"onboarding\",\"value\":\"onboarding\"})].context" is specified
ramonsnir commented 3 months ago

Thank you for reporting! We'll be adding automated tests to this resource soon.

SalehAly01 commented 3 months ago

Thank you, @ramonsnir, for the speedy fix. 🎉