Skip to content

Commit

Permalink
Folder: Prevent UID updates
Browse files Browse the repository at this point in the history
See grafana/grafana#74684
In Grafana 10.2, the API goes away
  • Loading branch information
julienduchesne committed Oct 31, 2023
1 parent cf237b5 commit 5221fd6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-openapi/strfmt v0.21.7
github.com/grafana/amixr-api-go-client v0.0.10
github.com/grafana/grafana-api-golang-client v0.24.0
github.com/grafana/grafana-openapi-client-go v0.0.0-20231025152211-949fda3a17a0
github.com/grafana/grafana-openapi-client-go v0.0.0-20231027173713-f32301dd8933
github.com/grafana/machine-learning-go-client v0.5.0
github.com/grafana/synthetic-monitoring-agent v0.18.3
github.com/grafana/synthetic-monitoring-api-go-client v0.7.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,10 @@ github.com/grafana/amixr-api-go-client v0.0.10 h1:L2Wc1aETiG7ORqmB+XSCBJdncHM/V0
github.com/grafana/amixr-api-go-client v0.0.10/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
github.com/grafana/grafana-api-golang-client v0.24.0 h1:9cUvft7xCMnnL/Uscwy7eoldn16Gz5TH4T1MymuVs8E=
github.com/grafana/grafana-api-golang-client v0.24.0/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231025152211-949fda3a17a0 h1:DeH1i5ORbYQnhlB2vpB4H5iSHrALPfDgr3qGx0uBApM=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231025152211-949fda3a17a0/go.mod h1:2vJ8YEgriYoHaNg5eijRU/q7eJTxT078VrGRSTTLeRk=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231027173713-f32301dd8933 h1:f9T8CpjLy13ADmBeE3W6Lj+FWaDYBNb+f/MU33/cUig=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231027173713-f32301dd8933/go.mod h1:2vJ8YEgriYoHaNg5eijRU/q7eJTxT078VrGRSTTLeRk=
github.com/grafana/machine-learning-go-client v0.5.0 h1:Q1K+MPSy8vfMm2jsk3WQ7O77cGr2fM5hxwtPSoPc5NU=
github.com/grafana/machine-learning-go-client v0.5.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
github.com/grafana/synthetic-monitoring-agent v0.18.2 h1:YW92rw38q3QB2dY34UK+O0a/735PlHLk4zWcOzrTro0=
github.com/grafana/synthetic-monitoring-agent v0.18.2/go.mod h1:TZzTibceWuSz/vb8K8JpdfAucuMctDCAKN7R0EaDIO4=
github.com/grafana/synthetic-monitoring-agent v0.18.3 h1:yPCWz7YFP7NU2rlZ5WPnEcZXWD8OnrGdNjRLsUZUgsw=
github.com/grafana/synthetic-monitoring-agent v0.18.3/go.mod h1:ftVjPOePRwkG7kGeFWI/6ZBEEHI9CdZjMyXqqFWvRVI=
github.com/grafana/synthetic-monitoring-api-go-client v0.7.0 h1:3ZfQzmXDBPcQTTgMAIIiTw5Dwxm/B4lzf34Sto0d0YY=
Expand Down
5 changes: 1 addition & 4 deletions internal/resources/grafana/resource_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func ResourceFolder() *schema.Resource {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: "Unique identifier.",
},
"title": {
Expand Down Expand Up @@ -101,10 +102,6 @@ func UpdateFolder(ctx context.Context, d *schema.ResourceData, meta interface{})
}).
WithFolderUID(folder.UID)

if newUID := d.Get("uid").(string); newUID != "" {
params.Body.UID = newUID
}

if _, err := client.Folders.UpdateFolder(params, nil); err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 1 addition & 7 deletions internal/resources/grafana/resource_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,16 @@ func TestAccFolder_basic(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"prevent_destroy_if_not_empty"},
},
// Change the title of one folder, change the UID of the other. They shouldn't change IDs (the folder doesn't have to be recreated)
// Change the title of a folder. This shouldn't change the ID (the folder doesn't have to be recreated)
{
Config: testutils.TestAccExampleWithReplace(t, "resources/grafana_folder/resource.tf", map[string]string{
"Terraform Test Folder": "Terraform Test Folder Updated",
"test-folder-uid": "test-folder-uid-other",
}),
Check: resource.ComposeTestCheckFunc(
testAccFolderIDDidntChange("grafana_folder.test_folder", &folder),
resource.TestMatchResourceAttr("grafana_folder.test_folder", "id", defaultOrgIDRegexp),
resource.TestMatchResourceAttr("grafana_folder.test_folder", "uid", common.UIDRegexp),
resource.TestCheckResourceAttr("grafana_folder.test_folder", "title", "Terraform Test Folder Updated"),

testAccFolderIDDidntChange("grafana_folder.test_folder_with_uid", &folderWithUID),
resource.TestMatchResourceAttr("grafana_folder.test_folder_with_uid", "id", defaultOrgIDRegexp),
resource.TestCheckResourceAttr("grafana_folder.test_folder_with_uid", "uid", "test-folder-uid-other"),
resource.TestCheckResourceAttr("grafana_folder.test_folder_with_uid", "title", "Terraform Test Folder Updated With UID"),
),
},
// Test import using ID
Expand Down

0 comments on commit 5221fd6

Please sign in to comment.