diff --git a/internal/provider/resources/group.go b/internal/provider/resources/group.go index 37f60cd3..2f931992 100644 --- a/internal/provider/resources/group.go +++ b/internal/provider/resources/group.go @@ -219,7 +219,11 @@ func (r *groupResource) Update( // Update the state to match the plan (replace with response from client) plan.ID = types.StringValue(group.Id) plan.Name = types.StringValue(group.Name) - plan.ParentGroupId = types.StringValue(group.Parent.Id) + // only update parent if not attached to root node (else leave it as null) + parentGroup, _ := r.getGroup(ctx, group.Parent.Id) + if parentGroup != nil && !util.IsRoot(*parentGroup) { + state.ParentGroupId = types.StringValue(group.Parent.Id) + } // Set state to fully populated data diags = resp.State.Set(ctx, plan) diff --git a/test/live/config/config.go b/test/live/config/config.go index 4f9343ec..ddd9a23e 100644 --- a/test/live/config/config.go +++ b/test/live/config/config.go @@ -1,8 +1,8 @@ package config -const WiredNetworkUid = "ethernet-658f93b6ea49" +const WiredNetworkUid = "ethernet-0ee5b46c2ef0" const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0" -const WirelessNetworkUid = "ssid-35e69ecab0c3" +const WirelessNetworkUid = "ssid-bf704ff37dc0" const WirelessNetworkName = "tf-provider-acceptance-tests-ssid-0" -const ServiceTestUid = "f0e703cb-9170-4da9-aa64-acf7379af3c3" +const ServiceTestUid = "6f81e43d-76f1-4a15-aafe-4ce2371d918a" const ServiceTestName = "tf-provider-acceptance-test-0" diff --git a/test/live/resources/group_test.go b/test/live/resources/group_test.go index feeb19f0..4fe28540 100644 --- a/test/live/resources/group_test.go +++ b/test/live/resources/group_test.go @@ -17,6 +17,13 @@ type Fetcher interface { var rootGroup = util.GetRoot() func TestGroupResource(t *testing.T) { + const groupNameParent = "tf_provider_acceptance_test_parent" + const groupNameParentUpdated = groupNameParent + "_updated" + const groupNameChild = "tf_provider_acceptance_test_child" + const groupNameGrandChild = "tf_provider_acceptance_test_grandchild" + const groupNameGrandChildMovedToParent = groupNameGrandChild + "_moved_to_parent" + const groupNameGrandChildMovedToRoot = groupNameGrandChild + "_moved_to_root" + resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, Steps: []resource.TestStep{ @@ -25,19 +32,13 @@ func TestGroupResource(t *testing.T) { // Node without parent (attached to root) Config: provider.ProviderConfig + ` resource "uxi_group" "parent" { - name = "tf_provider_acceptance_test_parent" + name = "` + groupNameParent + `" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( - "uxi_group.parent", - "name", - "tf_provider_acceptance_test_parent", - ), - resource.TestCheckResourceAttrPtr( - "uxi_group.parent", - "parent_group_id", - nil, + "uxi_group.parent", "name", groupNameParent, ), + resource.TestCheckNoResourceAttr("uxi_group.parent", "parent_group_id"), ), }, // ImportState testing @@ -50,18 +51,17 @@ func TestGroupResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_group" "parent" { - name = "tf_provider_acceptance_test_parent_name_updated" + name = "` + groupNameParentUpdated + `" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "uxi_group.parent", "name", - "tf_provider_acceptance_test_parent_name_updated", + groupNameParentUpdated, ), - resource.TestCheckResourceAttrPtr( + resource.TestCheckNoResourceAttr( "uxi_group.parent", "parent_group_id", - &rootGroup.Id, ), ), }, @@ -69,46 +69,41 @@ func TestGroupResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_group" "parent" { - name = "tf_provider_acceptance_test_parent_name_updated" + name = "` + groupNameParentUpdated + `" } resource "uxi_group" "child" { - name = "tf_provider_acceptance_test_child" + name = "` + groupNameChild + `" parent_group_id = uxi_group.parent.id } resource "uxi_group" "grandchild" { - name = "tf_provider_acceptance_test_grandchild" + name = "` + groupNameGrandChild + `" parent_group_id = uxi_group.child.id }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "uxi_group.child", "name", - "tf_provider_acceptance_test_child", + groupNameChild, ), resource.TestCheckResourceAttrWith( "uxi_group.child", "parent_group_id", func(parentGroupId string) error { - return checkGroupIsChildOfNode( - parentGroupId, - "tf_provider_acceptance_test_parent_name_updated", - ) + return checkGroupIsChildOfNode(parentGroupId, groupNameParentUpdated) }, ), resource.TestCheckResourceAttr( "uxi_group.grandchild", "name", - "tf_provider_acceptance_test_grandchild", + groupNameGrandChild, ), resource.TestCheckResourceAttrWith( "uxi_group.grandchild", "parent_group_id", func(parentGroupId string) error { - return checkGroupIsChildOfNode( - parentGroupId, "tf_provider_acceptance_test_child", - ) + return checkGroupIsChildOfNode(parentGroupId, groupNameChild) }, ), ), @@ -117,33 +112,30 @@ func TestGroupResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_group" "parent" { - name = "tf_provider_acceptance_test_parent_name_updated" + name = "` + groupNameParentUpdated + `" } resource "uxi_group" "child" { - name = "tf_provider_acceptance_test_child" + name = "` + groupNameChild + `" parent_group_id = uxi_group.parent.id } # move grandchild from child to parent resource "uxi_group" "grandchild" { - name = "tf_provider_acceptance_test_grandchild_moved_to_parent" + name = "` + groupNameGrandChildMovedToParent + `" parent_group_id = uxi_group.parent.id }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "uxi_group.grandchild", "name", - "tf_provider_acceptance_test_grandchild_moved_to_parent", + groupNameGrandChildMovedToParent, ), resource.TestCheckResourceAttrWith( "uxi_group.grandchild", "parent_group_id", func(parentGroupId string) error { - return checkGroupIsChildOfNode( - parentGroupId, - "tf_provider_acceptance_test_parent_name_updated", - ) + return checkGroupIsChildOfNode(parentGroupId, groupNameParentUpdated) }, ), ), @@ -152,28 +144,27 @@ func TestGroupResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_group" "parent" { - name = "tf_provider_acceptance_test_parent_name_updated" + name = "` + groupNameParentUpdated + `" } resource "uxi_group" "child" { - name = "tf_provider_acceptance_test_child" + name = "` + groupNameChild + `" parent_group_id = uxi_group.parent.id } # move grandchild from parent to root resource "uxi_group" "grandchild" { - name = "tf_provider_acceptance_test_grandchild_moved_to_root" + name = "` + groupNameGrandChildMovedToRoot + `" }`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "uxi_group.grandchild", "name", - "tf_provider_acceptance_test_grandchild_moved_to_root", + groupNameGrandChildMovedToRoot, ), - resource.TestCheckResourceAttr( + resource.TestCheckNoResourceAttr( "uxi_group.grandchild", "parent_group_id", - rootGroup.Id, ), ), }, diff --git a/test/live/resources/wired_network_test.go b/test/live/resources/wired_network_test.go index 4283b371..db148dd8 100644 --- a/test/live/resources/wired_network_test.go +++ b/test/live/resources/wired_network_test.go @@ -33,7 +33,7 @@ func TestWiredNetworkResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_wired_network" "wired_network_0" { - name = "tf-provider-acceptance-tests-ethernet-0" + name = "` + config.WiredNetworkName + `" } import { @@ -45,7 +45,7 @@ func TestWiredNetworkResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_wired_network.wired_network_0", "name", - "tf-provider-acceptance-tests-ethernet-0", + config.WiredNetworkName, ), resource.TestCheckResourceAttr( "uxi_wired_network.wired_network_0", @@ -64,7 +64,7 @@ func TestWiredNetworkResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_wired_network" "wired_network_0" { - name = "tf-provider-acceptance-tests-ethernet-0-updated-name" + name = "` + config.WiredNetworkUid + `-updated-name" }`, ExpectError: regexp.MustCompile( `(?s)updating a wired_network is not supported; wired_networks can only be updated\s*through the dashboard`, diff --git a/test/live/resources/wireless_network_test.go b/test/live/resources/wireless_network_test.go index ff2a6689..7470d01c 100644 --- a/test/live/resources/wireless_network_test.go +++ b/test/live/resources/wireless_network_test.go @@ -33,7 +33,7 @@ func TestWirelessNetworkResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_wireless_network" "wireless_network_0" { - name = "tf-provider-acceptance-tests-ssid-0" + name = "` + config.WirelessNetworkName + `" } import { @@ -45,7 +45,7 @@ func TestWirelessNetworkResource(t *testing.T) { resource.TestCheckResourceAttr( "uxi_wireless_network.wireless_network_0", "name", - "tf-provider-acceptance-tests-ssid-0", + config.WirelessNetworkName, ), resource.TestCheckResourceAttr( "uxi_wireless_network.wireless_network_0", @@ -64,7 +64,7 @@ func TestWirelessNetworkResource(t *testing.T) { { Config: provider.ProviderConfig + ` resource "uxi_wireless_network" "wireless_network_0" { - name = "tf-provider-acceptance-tests-ssid-0-updated-name" + name = "` + config.WirelessNetworkName + `-updated-name" }`, ExpectError: regexp.MustCompile( `(?s)updating a wireless_network is not supported; wireless_networks can only be\s*updated through the dashboard`,