@@ -78,6 +78,8 @@ func TestAccSumologicHierarchy_create(t *testing.T) {
7878 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "name" , testName ),
7979 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "filter.0.key" , testFilter .Key ),
8080 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "filter.0.value" , testFilter .Value ),
81+ resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "level.0.entity_type" ,
82+ testLevel .EntityType ),
8183 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" ,
8284 "level.0.next_levels_with_conditions.0.condition" ,
8385 testLevel .NextLevelsWithConditions [0 ].Condition ),
@@ -93,45 +95,27 @@ func TestAccSumologicHierarchy_create(t *testing.T) {
9395 })
9496}
9597
96- func testAccCheckHierarchyDestroy (hierarchy Hierarchy ) resource.TestCheckFunc {
97- return func (s * terraform.State ) error {
98- client := testAccProvider .Meta ().(* Client )
99- for _ , r := range s .RootModule ().Resources {
100- id := r .Primary .ID
101- u , err := client .GetHierarchy (id )
102- if err != nil {
103- return fmt .Errorf ("Encountered an error: " + err .Error ())
104- }
105- if u != nil {
106- return fmt .Errorf ("Hierarchy %s still exists" , id )
107- }
108- }
109- return nil
110- }
111- }
112-
113- func testAccCheckHierarchyExists (name string , hierarchy * Hierarchy , t * testing.T ) resource.TestCheckFunc {
114- return func (s * terraform.State ) error {
115- rs , ok := s .RootModule ().Resources [name ]
116- if ! ok {
117- //need this so that we don't get an unused import error for strconv in some cases
118- return fmt .Errorf ("Error = %s. Hierarchy not found: %s" , strconv .FormatBool (ok ), name )
119- }
120-
121- //need this so that we don't get an unused import error for strings in some cases
122- if strings .EqualFold (rs .Primary .ID , "" ) {
123- return fmt .Errorf ("Hierarchy ID is not set" )
124- }
98+ func TestAccSumologicHierarchy_createAlmostEmpty (t * testing.T ) {
99+ var hierarchy Hierarchy
100+ testName , _ , testLevel := getRandomizedParamsForHierarchy ()
125101
126- id := rs .Primary .ID
127- c := testAccProvider .Meta ().(* Client )
128- newHierarchy , err := c .GetHierarchy (id )
129- if err != nil {
130- return fmt .Errorf ("Hierarchy %s not found" , id )
131- }
132- hierarchy = newHierarchy
133- return nil
134- }
102+ resource .Test (t , resource.TestCase {
103+ PreCheck : func () { testAccPreCheck (t ) },
104+ Providers : testAccProviders ,
105+ CheckDestroy : testAccCheckHierarchyDestroy (hierarchy ),
106+ Steps : []resource.TestStep {
107+ {
108+ Config : testAccSumologicHierarchyAlmostEmpty (testName , testLevel ),
109+ Check : resource .ComposeTestCheckFunc (
110+ testAccCheckHierarchyExists ("sumologic_hierarchy.test" , & hierarchy , t ),
111+ resource .TestCheckResourceAttrSet ("sumologic_hierarchy.test" , "id" ),
112+ resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "name" , testName ),
113+ resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "level.0.entity_type" ,
114+ testLevel .EntityType ),
115+ ),
116+ },
117+ },
118+ })
135119}
136120
137121func TestAccSumologicHierarchy_update (t * testing.T ) {
@@ -153,6 +137,8 @@ func TestAccSumologicHierarchy_update(t *testing.T) {
153137 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "name" , testName ),
154138 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "filter.0.key" , testFilter .Key ),
155139 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "filter.0.value" , testFilter .Value ),
140+ resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "level.0.entity_type" ,
141+ testLevel .EntityType ),
156142 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" ,
157143 "level.0.next_levels_with_conditions.0.condition" ,
158144 testLevel .NextLevelsWithConditions [0 ].Condition ),
@@ -172,6 +158,8 @@ func TestAccSumologicHierarchy_update(t *testing.T) {
172158 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "name" , testUpdatedName ),
173159 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "filter.0.key" , testUpdatedFilter .Key ),
174160 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "filter.0.value" , testUpdatedFilter .Value ),
161+ resource .TestCheckResourceAttr ("sumologic_hierarchy.test" , "level.0.entity_type" ,
162+ testUpdatedLevel .EntityType ),
175163 resource .TestCheckResourceAttr ("sumologic_hierarchy.test" ,
176164 "level.0.next_levels_with_conditions.0.condition" ,
177165 testUpdatedLevel .NextLevelsWithConditions [0 ].Condition ),
@@ -187,6 +175,47 @@ func TestAccSumologicHierarchy_update(t *testing.T) {
187175 })
188176}
189177
178+ func testAccCheckHierarchyDestroy (hierarchy Hierarchy ) resource.TestCheckFunc {
179+ return func (s * terraform.State ) error {
180+ client := testAccProvider .Meta ().(* Client )
181+ for _ , r := range s .RootModule ().Resources {
182+ id := r .Primary .ID
183+ u , err := client .GetHierarchy (id )
184+ if err != nil {
185+ return fmt .Errorf ("Encountered an error: " + err .Error ())
186+ }
187+ if u != nil {
188+ return fmt .Errorf ("Hierarchy %s still exists" , id )
189+ }
190+ }
191+ return nil
192+ }
193+ }
194+
195+ func testAccCheckHierarchyExists (name string , hierarchy * Hierarchy , t * testing.T ) resource.TestCheckFunc {
196+ return func (s * terraform.State ) error {
197+ rs , ok := s .RootModule ().Resources [name ]
198+ if ! ok {
199+ //need this so that we don't get an unused import error for strconv in some cases
200+ return fmt .Errorf ("Error = %s. Hierarchy not found: %s" , strconv .FormatBool (ok ), name )
201+ }
202+
203+ //need this so that we don't get an unused import error for strings in some cases
204+ if strings .EqualFold (rs .Primary .ID , "" ) {
205+ return fmt .Errorf ("Hierarchy ID is not set" )
206+ }
207+
208+ id := rs .Primary .ID
209+ c := testAccProvider .Meta ().(* Client )
210+ newHierarchy , err := c .GetHierarchy (id )
211+ if err != nil {
212+ return fmt .Errorf ("Hierarchy %s not found" , id )
213+ }
214+ hierarchy = newHierarchy
215+ return nil
216+ }
217+ }
218+
190219func testAccCheckSumologicHierarchyConfigImported (name string , filter HierarchyFilteringClause , level Level ) string {
191220 return fmt .Sprintf (`
192221 resource "sumologic_hierarchy" "test" {
@@ -235,6 +264,17 @@ func testAccSumologicHierarchy(name string, filter HierarchyFilteringClause, lev
235264 level .NextLevelsWithConditions [0 ].Level .EntityType , level .NextLevel .EntityType )
236265}
237266
267+ func testAccSumologicHierarchyAlmostEmpty (name string , level Level ) string {
268+ return fmt .Sprintf (`
269+ resource "sumologic_hierarchy" "test" {
270+ name = "%s"
271+ level {
272+ entity_type = "%s"
273+ }
274+ }` ,
275+ name , level .EntityType )
276+ }
277+
238278func testAccSumologicHierarchyUpdate (name string , filter HierarchyFilteringClause , level Level ) string {
239279 return fmt .Sprintf (`
240280 resource "sumologic_hierarchy" "test" {
0 commit comments