Skip to content

Commit 9f0400e

Browse files
feat: normalize cortex agent show/describe output representations (#4786)
## Changes * Use non-nil strings for comment and CortexAgentProfile for profile. * Normalize agent_spec in SDK describe conversion to stable JSON. * Update schemas, docs, and assertions to use profile as a nested block. * Adjust acceptance/integration tests to assert typed profile and spec. * Bump terraform-plugin-testing to v1.16.0.
1 parent 9f08944 commit 9f0400e

23 files changed

Lines changed: 260 additions & 224 deletions

docs/data-sources/cortex_agents.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,20 @@ Read-Only:
185185
- `default_version_name` (String)
186186
- `name` (String)
187187
- `owner` (String)
188-
- `profile` (String)
188+
- `profile` (List of Object) (see [below for nested schema](#nestedobjatt--cortex_agents--describe_output--profile))
189189
- `schema_name` (String)
190190
- `versions` (String)
191191

192+
<a id="nestedobjatt--cortex_agents--describe_output--profile"></a>
193+
### Nested Schema for `cortex_agents.describe_output.profile`
194+
195+
Read-Only:
196+
197+
- `avatar` (String)
198+
- `color` (String)
199+
- `display_name` (String)
200+
201+
192202

193203
<a id="nestedobjatt--cortex_agents--show_output"></a>
194204
### Nested Schema for `cortex_agents.show_output`
@@ -200,5 +210,14 @@ Read-Only:
200210
- `database_name` (String)
201211
- `name` (String)
202212
- `owner` (String)
203-
- `profile` (String)
213+
- `profile` (List of Object) (see [below for nested schema](#nestedobjatt--cortex_agents--show_output--profile))
204214
- `schema_name` (String)
215+
216+
<a id="nestedobjatt--cortex_agents--show_output--profile"></a>
217+
### Nested Schema for `cortex_agents.show_output.profile`
218+
219+
Read-Only:
220+
221+
- `avatar` (String)
222+
- `color` (String)
223+
- `display_name` (String)

docs/resources/cortex_agent.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,20 @@ Read-Only:
119119
- `default_version_name` (String)
120120
- `name` (String)
121121
- `owner` (String)
122-
- `profile` (String)
122+
- `profile` (List of Object) (see [below for nested schema](#nestedobjatt--describe_output--profile))
123123
- `schema_name` (String)
124124
- `versions` (String)
125125

126+
<a id="nestedobjatt--describe_output--profile"></a>
127+
### Nested Schema for `describe_output.profile`
128+
129+
Read-Only:
130+
131+
- `avatar` (String)
132+
- `color` (String)
133+
- `display_name` (String)
134+
135+
126136

127137
<a id="nestedatt--show_output"></a>
128138
### Nested Schema for `show_output`
@@ -134,9 +144,18 @@ Read-Only:
134144
- `database_name` (String)
135145
- `name` (String)
136146
- `owner` (String)
137-
- `profile` (String)
147+
- `profile` (List of Object) (see [below for nested schema](#nestedobjatt--show_output--profile))
138148
- `schema_name` (String)
139149

150+
<a id="nestedobjatt--show_output--profile"></a>
151+
### Nested Schema for `show_output.profile`
152+
153+
Read-Only:
154+
155+
- `avatar` (String)
156+
- `color` (String)
157+
- `display_name` (String)
158+
140159
## Import
141160

142161
Import is supported using the following syntax:

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/hashicorp/terraform-plugin-go v0.31.0
1515
github.com/hashicorp/terraform-plugin-mux v0.23.1
1616
github.com/hashicorp/terraform-plugin-sdk/v2 v2.40.0
17-
github.com/hashicorp/terraform-plugin-testing v1.15.0
17+
github.com/hashicorp/terraform-plugin-testing v1.16.0
1818
github.com/jmoiron/sqlx v1.4.0
1919
github.com/pelletier/go-toml/v2 v2.3.1
2020
github.com/snowflakedb/gosnowflake/v2 v2.0.2
@@ -80,10 +80,10 @@ require (
8080
github.com/hashicorp/go-plugin v1.8.0 // indirect
8181
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
8282
github.com/hashicorp/go-version v1.9.0 // indirect
83-
github.com/hashicorp/hc-install v0.9.3 // indirect
83+
github.com/hashicorp/hc-install v0.9.4 // indirect
8484
github.com/hashicorp/hcl/v2 v2.24.0 // indirect
8585
github.com/hashicorp/logutils v1.0.0 // indirect
86-
github.com/hashicorp/terraform-exec v0.25.0 // indirect
86+
github.com/hashicorp/terraform-exec v0.25.1 // indirect
8787
github.com/hashicorp/terraform-plugin-log v0.10.0 // indirect
8888
github.com/hashicorp/terraform-registry-address v0.4.0 // indirect
8989
github.com/hashicorp/terraform-svchost v0.2.1 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9
100100
github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
101101
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
102102
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
103-
github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM=
104-
github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU=
105-
github.com/go-git/go-git/v5 v5.16.5 h1:mdkuqblwr57kVfXri5TTH+nMFLNUxIj9Z7F5ykFbw5s=
106-
github.com/go-git/go-git/v5 v5.16.5/go.mod h1:QOMLpNf1qxuSY4StA/ArOdfFR2TrKEjJiye2kel2m+M=
103+
github.com/go-git/go-billy/v5 v5.8.0 h1:I8hjc3LbBlXTtVuFNJuwYuMiHvQJDq1AT6u4DwDzZG0=
104+
github.com/go-git/go-billy/v5 v5.8.0/go.mod h1:RpvI/rw4Vr5QA+Z60c6d6LXH0rYJo0uD5SqfmrrheCY=
105+
github.com/go-git/go-git/v5 v5.18.0 h1:O831KI+0PR51hM2kep6T8k+w0/LIAD490gvqMCvL5hM=
106+
github.com/go-git/go-git/v5 v5.18.0/go.mod h1:pW/VmeqkanRFqR6AljLcs7EA7FbZaN5MQqO7oZADXpo=
107107
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
108108
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
109109
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -162,16 +162,16 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
162162
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
163163
github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA=
164164
github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
165-
github.com/hashicorp/hc-install v0.9.3 h1:1H4dgmgzxEVwT6E/d/vIL5ORGVKz9twRwDw+qA5Hyho=
166-
github.com/hashicorp/hc-install v0.9.3/go.mod h1:FQlQ5I3I/X409N/J1U4pPeQQz1R3BoV0IysB7aiaQE0=
165+
github.com/hashicorp/hc-install v0.9.4 h1:KKWOpUG0EqIV63Qk2GGFrZ0s275NVs5lKf9N5vjBNoc=
166+
github.com/hashicorp/hc-install v0.9.4/go.mod h1:4LRYeEN2bMIFfIv57ldMWt9awfuZhvpbRt0vWmv51WU=
167167
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
168168
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
169169
github.com/hashicorp/hcl/v2 v2.24.0 h1:2QJdZ454DSsYGoaE6QheQZjtKZSUs9Nh2izTWiwQxvE=
170170
github.com/hashicorp/hcl/v2 v2.24.0/go.mod h1:oGoO1FIQYfn/AgyOhlg9qLC6/nOJPX3qGbkZpYAcqfM=
171171
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
172172
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
173-
github.com/hashicorp/terraform-exec v0.25.0 h1:Bkt6m3VkJqYh+laFMrWIpy9KHYFITpOyzRMNI35rNaY=
174-
github.com/hashicorp/terraform-exec v0.25.0/go.mod h1:dl9IwsCfklDU6I4wq9/StFDp7dNbH/h5AnfS1RmiUl8=
173+
github.com/hashicorp/terraform-exec v0.25.1 h1:PRutYRGM8pixV3B8812NYoBK5O+yuf3qcB/70KFKGiU=
174+
github.com/hashicorp/terraform-exec v0.25.1/go.mod h1:+izOYrs9sKMQK4OYvGDnrSSJHY/pm4e4eXFqSL2Q5mA=
175175
github.com/hashicorp/terraform-json v0.27.2 h1:BwGuzM6iUPqf9JYM/Z4AF1OJ5VVJEEzoKST/tRDBJKU=
176176
github.com/hashicorp/terraform-json v0.27.2/go.mod h1:GzPLJ1PLdUG5xL6xn1OXWIjteQRT2CNT9o/6A9mi9hE=
177177
github.com/hashicorp/terraform-plugin-framework v1.19.0 h1:q0bwyhxAOR3vfdgbk9iplv3MlTv/dhBHTXjQOtQDoBA=
@@ -186,8 +186,8 @@ github.com/hashicorp/terraform-plugin-mux v0.23.1 h1:B93b4hEj8cPKh24WJH2dJJAS3a5
186186
github.com/hashicorp/terraform-plugin-mux v0.23.1/go.mod h1:IwuivHNfDVeuDbVvg6fnAYEEEVx881STwJHsl/00UkQ=
187187
github.com/hashicorp/terraform-plugin-sdk/v2 v2.40.0 h1:MKS/2URqeJRwJdbOfcbdsZCq/IRrNkqJNN0GtVIsuGs=
188188
github.com/hashicorp/terraform-plugin-sdk/v2 v2.40.0/go.mod h1:PuG4P97Ju3QXW6c6vRkRadWJbvnEu2Xh+oOuqcYOqX4=
189-
github.com/hashicorp/terraform-plugin-testing v1.15.0 h1:/fimKyl0YgD7aAtJkuuAZjwBASXhCIwWqMbDLnKLMe4=
190-
github.com/hashicorp/terraform-plugin-testing v1.15.0/go.mod h1:bGXMw7bE95EiZhSBV3rM2W8TiffaPTDuLS+HFI/lIYs=
189+
github.com/hashicorp/terraform-plugin-testing v1.16.0 h1:GB97nGnJ1hESpDrCjqZig38RodSF0gdRzxlDupLXP38=
190+
github.com/hashicorp/terraform-plugin-testing v1.16.0/go.mod h1:eQPYAy9xFMV7xtIFX8Y+wJGtUB++HBl329zCF6PBMZk=
191191
github.com/hashicorp/terraform-registry-address v0.4.0 h1:S1yCGomj30Sao4l5BMPjTGZmCNzuv7/GDTDX99E9gTk=
192192
github.com/hashicorp/terraform-registry-address v0.4.0/go.mod h1:LRS1Ay0+mAiRkUyltGT+UHWkIqTFvigGn/LbMshfflE=
193193
github.com/hashicorp/terraform-svchost v0.2.1 h1:ubvrTFw3Q7CsoEaX7V06PtCTKG3wu7GyyobAoN4eF3Q=

pkg/acceptance/bettertestspoc/assert/objectassert/cortex_agent_desc_snowflake_ext.go

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,13 @@ package objectassert
22

33
import (
44
"fmt"
5+
"reflect"
56
"testing"
67
"time"
78

89
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
9-
"github.com/stretchr/testify/require"
1010
)
1111

12-
func (c *CortexAgentDetailsAssert) HasNoComment() *CortexAgentDetailsAssert {
13-
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgentDetails) error {
14-
t.Helper()
15-
if o.Comment != nil {
16-
return fmt.Errorf("expected comment to be empty")
17-
}
18-
return nil
19-
})
20-
return c
21-
}
22-
23-
func (c *CortexAgentDetailsAssert) HasNoProfile() *CortexAgentDetailsAssert {
24-
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgentDetails) error {
25-
t.Helper()
26-
if o.Profile != nil {
27-
return fmt.Errorf("expected profile to be empty")
28-
}
29-
return nil
30-
})
31-
return c
32-
}
33-
3412
func (c *CortexAgentDetailsAssert) HasCreatedOnNotEmpty() *CortexAgentDetailsAssert {
3513
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgentDetails) error {
3614
t.Helper()
@@ -45,21 +23,8 @@ func (c *CortexAgentDetailsAssert) HasCreatedOnNotEmpty() *CortexAgentDetailsAss
4523
func (c *CortexAgentDetailsAssert) HasCortexAgentProfile(expected sdk.CortexAgentProfile) *CortexAgentDetailsAssert {
4624
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgentDetails) error {
4725
t.Helper()
48-
return assertCortexAgentProfileJsonEqual(o.Profile, expected)
49-
})
50-
return c
51-
}
52-
53-
func (c *CortexAgentDetailsAssert) HasCortexAgentSpec(expected string) *CortexAgentDetailsAssert {
54-
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgentDetails) error {
55-
t.Helper()
56-
normalizedActual, err := sdk.NormalizeCortexAgentSpecification(o.AgentSpec)
57-
require.NoError(t, err)
58-
normalizedExpected, err := sdk.NormalizeCortexAgentSpecification(expected)
59-
require.NoError(t, err)
60-
61-
if normalizedActual != normalizedExpected {
62-
return fmt.Errorf("expected agent spec: %v; got: %v", normalizedExpected, normalizedActual)
26+
if !reflect.DeepEqual(o.Profile, expected) {
27+
return fmt.Errorf("expected profile: %+v; got: %+v", expected, o.Profile)
6328
}
6429
return nil
6530
})

pkg/acceptance/bettertestspoc/assert/objectassert/cortex_agent_desc_snowflake_gen.go

Lines changed: 5 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/acceptance/bettertestspoc/assert/objectassert/cortex_agent_snowflake_ext.go

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ import (
99
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
1010
)
1111

12-
func (c *CortexAgentAssert) HasNoComment() *CortexAgentAssert {
13-
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgent) error {
14-
t.Helper()
15-
if o.Comment != nil {
16-
return fmt.Errorf("expected comment to be empty")
17-
}
18-
return nil
19-
})
20-
return c
21-
}
22-
23-
func (c *CortexAgentAssert) HasNoProfile() *CortexAgentAssert {
24-
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgent) error {
25-
t.Helper()
26-
if o.Profile != nil {
27-
return fmt.Errorf("expected profile to be empty")
28-
}
29-
return nil
30-
})
31-
return c
32-
}
33-
3412
func (c *CortexAgentAssert) HasCreatedOnNotEmpty() *CortexAgentAssert {
3513
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgent) error {
3614
t.Helper()
@@ -45,23 +23,10 @@ func (c *CortexAgentAssert) HasCreatedOnNotEmpty() *CortexAgentAssert {
4523
func (c *CortexAgentAssert) HasCortexAgentProfile(expected sdk.CortexAgentProfile) *CortexAgentAssert {
4624
c.AddAssertion(func(t *testing.T, o *sdk.CortexAgent) error {
4725
t.Helper()
48-
return assertCortexAgentProfileJsonEqual(o.Profile, expected)
26+
if !reflect.DeepEqual(o.Profile, expected) {
27+
return fmt.Errorf("expected profile: %+v; got: %+v", expected, o.Profile)
28+
}
29+
return nil
4930
})
5031
return c
5132
}
52-
53-
func assertCortexAgentProfileJsonEqual(profile *string, expected sdk.CortexAgentProfile) error {
54-
if profile == nil {
55-
return fmt.Errorf("expected profile to be non-nil")
56-
}
57-
58-
actual, err := sdk.UnmarshalCortexAgentProfile(*profile)
59-
if err != nil {
60-
return fmt.Errorf("unmarshal cortex agent profile: %w", err)
61-
}
62-
63-
if !reflect.DeepEqual(actual, &expected) {
64-
return fmt.Errorf("expected profile %+v; got %+v", &expected, actual)
65-
}
66-
return nil
67-
}

pkg/acceptance/bettertestspoc/assert/objectassert/cortex_agent_snowflake_gen.go

Lines changed: 5 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/cortex_agent_desc_output_ext.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@ package resourceshowoutputassert
22

33
import (
44
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
5+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
56
)
67

78
func (c *CortexAgentDescribeOutputAssert) HasCreatedOnNotEmpty() *CortexAgentDescribeOutputAssert {
89
c.AddAssertion(assert.ResourceDescribeOutputValuePresent("created_on"))
910
return c
1011
}
12+
13+
func (c *CortexAgentDescribeOutputAssert) HasProfile(expected sdk.CortexAgentProfile) *CortexAgentDescribeOutputAssert {
14+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.#", "1"))
15+
if expected.DisplayName != nil {
16+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.0.display_name", *expected.DisplayName))
17+
} else {
18+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.0.display_name", ""))
19+
}
20+
if expected.Avatar != nil {
21+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.0.avatar", *expected.Avatar))
22+
} else {
23+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.0.avatar", ""))
24+
}
25+
if expected.Color != nil {
26+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.0.color", *expected.Color))
27+
} else {
28+
c.AddAssertion(assert.ResourceDescribeOutputValueSet("profile.0.color", ""))
29+
}
30+
return c
31+
}

pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/cortex_agent_desc_output_gen.go

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)