Error 404 when modifying a protected environment name with a `/` in the name.
Bug Report
One of our customers reported an issue where they are seeing a 404 when modifying a protected environment.
gitlab_project_protected_environment.example_with_access_level: Modifying... [id=51004787:prod/finance]
╷
│ Error: GitLab Feature not available
│
│ with gitlab_project_protected_environment.example_with_access_level,
│ on main.tf line 18, in resource "gitlab_project_protected_environment" "example_with_access_level":
│ 18: resource "gitlab_project_protected_environment" "example_with_access_level" {
│
│ The protected environment feature is not available on this project. Make sure it's part of an enterprise plan. Error: PUT https://gitlab.com/api/v4/projects/51004787/protected_environments/prod/finance: 404 {error: 404 Not Found}
╵
It turns out that this happens if the environment name contains a /
, for example prod/finance
.
When using the API, GitLab requires /
to be URL encoded. It appears the Terraform module doesn't URL encode this slash when modifying a protected environment.
Relevant Terraform Configuration
terraform {
required_providers {
gitlab = {
source = "gitlabhq/gitlab"
}
}
}
variable "gitlab_token" {
type = string
sensitive = true
}
provider "gitlab" {
token = var.gitlab_token
}
resource "gitlab_project_protected_environment" "example_with_access_level" {
project = 51004787
required_approval_count = 2
environment = "prod/finance"
deploy_access_levels {
access_level = "developer"
}
}
Relevant Terraform Command
First create the protected environment by applying the terraform file above
terraform init
terraform plan
terraform apply
access_level
to maintainer
)
Reproduce the issue by modifying the protected environment by modifying the terraform file (e.g. changing terraform plan
terraform apply
Relevant Log Output
These are the debug logs of the `terraform` command output:
Additional Details
- GitLab Terraform Provider Version: 16.6.0
- GitLab Version: GitLab SaaS
- Terraform Version: 1.5.7