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

Ensure the correct env pointer is used after matching #92

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.3.4 (October 31, 2023). Tested on Artifactory 7.71.3 and Xray 3.83.10

BUG FIXES:

* resource/project_environment: Fix incorrect environment from Artifactroy being matched and triggers a state drift. Issue: [#90](https://github.com/jfrog/terraform-provider-project/issues/90) PR: [#92](https://github.com/jfrog/terraform-provider-project/pull/92)

## 1.3.3 (October 18, 2023)

IMPROVEMENTS:
Expand Down
4 changes: 3 additions & 1 deletion pkg/project/resource_project_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func projectEnvironmentResource() *schema.Resource {

var readProjectEnvironment = func(ctx context.Context, data *schema.ResourceData, m interface{}) diag.Diagnostics {
projectKey := data.Get("project_key").(string)
envs := []ProjectEnvironment{}
var envs []ProjectEnvironment

_, err := m.(util.ProvderMetadata).Client.R().
SetPathParam("projectKey", projectKey).
Expand All @@ -69,6 +69,7 @@ func projectEnvironmentResource() *schema.Resource {
for _, env := range envs {
if env.Name == fmt.Sprintf("%s-%s", projectKey, data.Get("name")) {
matchedEnv = &env
break
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! 🤦🏼‍♂️

}
}

Expand Down Expand Up @@ -123,6 +124,7 @@ func projectEnvironmentResource() *schema.Resource {
}

data.SetId(projectEnvironmentUpdate.Id())
data.Set("name", newName)

return readProjectEnvironment(ctx, data, m)
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/project/resource_project_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestAccProjectEnvironment(t *testing.T) {
resourceName := fmt.Sprintf("project_environment.%s", name)

params := map[string]any{
"env_id": name,
"name": name,
"project_key": projectKey,
}
Expand All @@ -33,7 +34,7 @@ func TestAccProjectEnvironment(t *testing.T) {
}
}

resource "project_environment" "{{ .name }}" {
resource "project_environment" "{{ .env_id }}" {
name = "{{ .name }}"
project_key = project.{{ .project_key }}.key
}
Expand All @@ -42,11 +43,12 @@ func TestAccProjectEnvironment(t *testing.T) {
enviroment := test.ExecuteTemplate("TestAccProjectEnvironment", template, params)

updateParams := map[string]any{
"name": name,
"env_id": name,
"name": fmt.Sprintf("env-%s", randSeq(10)),
"project_key": projectKey,
}

enviromentUpdated := test.ExecuteTemplate("TestAccProjects", template, updateParams)
enviromentUpdated := test.ExecuteTemplate("TestAccProjectEnvironment", template, updateParams)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
Loading