@@ -89,6 +89,90 @@ func TestAccTFEAgentPoolDataSource_allowed_workspaces(t *testing.T) {
89
89
})
90
90
}
91
91
92
+ func TestAccTFEAgentPoolDataSource_allowed_projects (t * testing.T ) {
93
+ skipIfEnterprise (t )
94
+
95
+ tfeClient , err := getClientUsingEnv ()
96
+ if err != nil {
97
+ t .Fatal (err )
98
+ }
99
+
100
+ org , orgCleanup := createBusinessOrganization (t , tfeClient )
101
+ t .Cleanup (orgCleanup )
102
+
103
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
104
+
105
+ ws , err := tfeClient .Projects .Create (ctx , org .Name , tfe.ProjectCreateOptions {
106
+ Name : fmt .Sprintf ("tst-proj-test-%d" , rInt ),
107
+ })
108
+ if err != nil {
109
+ t .Fatal (err )
110
+ }
111
+
112
+ resource .Test (t , resource.TestCase {
113
+ PreCheck : func () { testAccPreCheck (t ) },
114
+ ProtoV5ProviderFactories : testAccMuxedProviders ,
115
+ Steps : []resource.TestStep {
116
+ {
117
+ Config : testAccTFEAgentPoolDataSourceAllowedProjectsConfig (org .Name , rInt , ws .ID ),
118
+ Check : resource .ComposeAggregateTestCheckFunc (
119
+ resource .TestCheckResourceAttrSet ("data.tfe_agent_pool.foobar" , "id" ),
120
+ resource .TestCheckResourceAttr (
121
+ "data.tfe_agent_pool.foobar" , "name" , fmt .Sprintf ("agent-pool-test-%d" , rInt )),
122
+ resource .TestCheckResourceAttr (
123
+ "data.tfe_agent_pool.foobar" , "organization" , org .Name ),
124
+ resource .TestCheckResourceAttr (
125
+ "data.tfe_agent_pool.foobar" , "organization_scoped" , "false" ),
126
+ resource .TestCheckResourceAttr (
127
+ "data.tfe_agent_pool.foobar" , "allowed_project_ids.0" , ws .ID ),
128
+ ),
129
+ },
130
+ },
131
+ })
132
+ }
133
+
134
+ func TestAccTFEAgentPoolDataSource_excluded_workspaces (t * testing.T ) {
135
+ skipIfEnterprise (t )
136
+
137
+ tfeClient , err := getClientUsingEnv ()
138
+ if err != nil {
139
+ t .Fatal (err )
140
+ }
141
+
142
+ org , orgCleanup := createBusinessOrganization (t , tfeClient )
143
+ t .Cleanup (orgCleanup )
144
+
145
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
146
+
147
+ ws , err := tfeClient .Workspaces .Create (ctx , org .Name , tfe.WorkspaceCreateOptions {
148
+ Name : tfe .String (fmt .Sprintf ("tst-workspace-test-%d" , rInt )),
149
+ })
150
+ if err != nil {
151
+ t .Fatal (err )
152
+ }
153
+
154
+ resource .Test (t , resource.TestCase {
155
+ PreCheck : func () { testAccPreCheck (t ) },
156
+ ProtoV5ProviderFactories : testAccMuxedProviders ,
157
+ Steps : []resource.TestStep {
158
+ {
159
+ Config : testAccTFEAgentPoolDataSourceExcludedWorkspacesConfig (org .Name , rInt , ws .ID ),
160
+ Check : resource .ComposeAggregateTestCheckFunc (
161
+ resource .TestCheckResourceAttrSet ("data.tfe_agent_pool.foobar" , "id" ),
162
+ resource .TestCheckResourceAttr (
163
+ "data.tfe_agent_pool.foobar" , "name" , fmt .Sprintf ("agent-pool-test-%d" , rInt )),
164
+ resource .TestCheckResourceAttr (
165
+ "data.tfe_agent_pool.foobar" , "organization" , org .Name ),
166
+ resource .TestCheckResourceAttr (
167
+ "data.tfe_agent_pool.foobar" , "organization_scoped" , "false" ),
168
+ resource .TestCheckResourceAttr (
169
+ "data.tfe_agent_pool.foobar" , "excluded_workspace_ids.0" , ws .ID ),
170
+ ),
171
+ },
172
+ },
173
+ })
174
+ }
175
+
92
176
func testAccTFEAgentPoolDataSourceConfig (organization string , rInt int ) string {
93
177
return fmt .Sprintf (`
94
178
resource "tfe_agent_pool" "foobar" {
@@ -121,3 +205,43 @@ data "tfe_agent_pool" "foobar" {
121
205
depends_on = [ tfe_agent_pool_allowed_workspaces.foobar ]
122
206
}` , rInt , organization , workspaceID , organization )
123
207
}
208
+
209
+ func testAccTFEAgentPoolDataSourceAllowedProjectsConfig (organization string , rInt int , projectID string ) string {
210
+ return fmt .Sprintf (`
211
+ resource "tfe_agent_pool" "foobar" {
212
+ name = "agent-pool-test-%d"
213
+ organization = "%s"
214
+ organization_scoped = false
215
+ }
216
+
217
+ resource "tfe_agent_pool_allowed_projects" "foobar" {
218
+ agent_pool_id = tfe_agent_pool.foobar.id
219
+ allowed_project_ids = ["%s"]
220
+ }
221
+
222
+ data "tfe_agent_pool" "foobar" {
223
+ name = tfe_agent_pool.foobar.name
224
+ organization = "%s"
225
+ depends_on = [ tfe_agent_pool_allowed_projects.foobar ]
226
+ }` , rInt , organization , projectID , organization )
227
+ }
228
+
229
+ func testAccTFEAgentPoolDataSourceExcludedWorkspacesConfig (organization string , rInt int , workspaceID string ) string {
230
+ return fmt .Sprintf (`
231
+ resource "tfe_agent_pool" "foobar" {
232
+ name = "agent-pool-test-%d"
233
+ organization = "%s"
234
+ organization_scoped = false
235
+ }
236
+
237
+ resource "tfe_agent_pool_excluded_workspaces" "foobar" {
238
+ agent_pool_id = tfe_agent_pool.foobar.id
239
+ excluded_workspace_ids = ["%s"]
240
+ }
241
+
242
+ data "tfe_agent_pool" "foobar" {
243
+ name = tfe_agent_pool.foobar.name
244
+ organization = "%s"
245
+ depends_on = [ tfe_agent_pool_excluded_workspaces.foobar ]
246
+ }` , rInt , organization , workspaceID , organization )
247
+ }
0 commit comments