Skip to content

Commit 736db06

Browse files
authored
Merge pull request #1836 from hashicorp/TF-25152/stacks-agent-pool-support
Stacks agent pool support
2 parents 21cae0b + 7ee9deb commit 736db06

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
FEATURES:
44

55
* `r/tfe_registry_module`: Add `source_directory` and `tag_prefix` registry module support for private registry monorepository, which is a beta feature and not available to all users, by @jillirami ([#1800](https://github.com/hashicorp/terraform-provider-tfe/pull/1800))
6+
* `r/tfe_stack` Adds support for managing agent pools on a Stack, by @maed223 [#1836](https://github.com/hashicorp/terraform-provider-tfe/pull/1836)
67
* `r/tfe_terraform_version`: Adds support for specifying architecture-specific binaries using the `archs` attribute, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
78
* `r/tfe_opa_version`: Adds support for specifying architecture-specific binaries using the `archs` attribute, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
89
* `r/tfe_sentinel_version`: Adds support for specifying architecture-specific binaries using the `archs` attribute, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/hashicorp/terraform-provider-tfe
22

33
go 1.24.0
44

5-
toolchain go1.24.1
5+
toolchain go1.24.4
66

77
require (
88
github.com/agext/levenshtein v1.2.3 // indirect

internal/provider/resource_tfe_stack.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (r *resourceTFEStack) Schema(ctx context.Context, req resource.SchemaReques
8080
stringplanmodifier.RequiresReplace(),
8181
},
8282
},
83+
"agent_pool_id": schema.StringAttribute{
84+
Description: "The ID of an agent pool to assign to the stack",
85+
Optional: true,
86+
},
8387
"name": schema.StringAttribute{
8488
Description: "Name of the Stack",
8589
Required: true,
@@ -155,6 +159,12 @@ func (r *resourceTFEStack) Create(ctx context.Context, req resource.CreateReques
155159
}
156160
}
157161

162+
if !plan.AgentPoolID.IsNull() {
163+
options.AgentPool = &tfe.AgentPool{
164+
ID: plan.AgentPoolID.ValueString(),
165+
}
166+
}
167+
158168
if !plan.Description.IsNull() {
159169
options.Description = tfe.String(plan.Description.ValueString())
160170
}
@@ -251,6 +261,12 @@ func (r *resourceTFEStack) Update(ctx context.Context, req resource.UpdateReques
251261
options.VCSRepo = nil
252262
}
253263

264+
if !plan.AgentPoolID.IsNull() {
265+
options.AgentPool = &tfe.AgentPool{
266+
ID: plan.AgentPoolID.ValueString(),
267+
}
268+
}
269+
254270
tflog.Debug(ctx, "Updating stack")
255271
stack, err := r.config.Client.Stacks.Update(ctx, state.ID.ValueString(), options)
256272
if err != nil {

internal/provider/resource_tfe_stack_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestAccTFEStackResource_basic(t *testing.T) {
2727
Check: resource.ComposeAggregateTestCheckFunc(
2828
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "id"),
2929
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "project_id"),
30+
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "agent_pool_id"),
3031
resource.TestCheckResourceAttr("tfe_stack.foobar", "name", "example-stack"),
3132
resource.TestCheckResourceAttr("tfe_stack.foobar", "description", "Just an ordinary stack"),
3233
resource.TestCheckResourceAttr("tfe_stack.foobar", "vcs_repo.identifier", "brandonc/pet-nulls-stack"),
@@ -51,6 +52,11 @@ resource "tfe_organization" "foobar" {
5152
5253
}
5354
55+
resource "tfe_agent_pool" "foobar" {
56+
name = "agent-pool-test-example"
57+
organization = tfe_organization.foobar.name
58+
}
59+
5460
resource "tfe_project" "example" {
5561
name = "example"
5662
organization = tfe_organization.foobar.name
@@ -68,6 +74,7 @@ resource "tfe_stack" "foobar" {
6874
name = "example-stack"
6975
description = "Just an ordinary stack"
7076
project_id = tfe_project.example.id
77+
agent_pool_id = tfe_agent_pool.foobar.id
7178
7279
vcs_repo {
7380
identifier = "%s"
@@ -77,6 +84,63 @@ resource "tfe_stack" "foobar" {
7784
`, orgName, ghToken, ghRepoIdentifier)
7885
}
7986

87+
func TestAccTFEStackResource_withAgentPool(t *testing.T) {
88+
skipUnlessBeta(t)
89+
90+
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
91+
orgName := fmt.Sprintf("tst-terraform-%d", rInt)
92+
93+
resource.Test(t, resource.TestCase{
94+
PreCheck: func() { testAccPreCheck(t) },
95+
ProtoV6ProviderFactories: testAccMuxedProviders,
96+
Steps: []resource.TestStep{
97+
{
98+
Config: testAccTFEStackResourceConfigWithAgentPool(orgName),
99+
Check: resource.ComposeAggregateTestCheckFunc(
100+
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "id"),
101+
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "project_id"),
102+
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "agent_pool_id"),
103+
resource.TestCheckResourceAttr("tfe_stack.foobar", "name", "example-stack"),
104+
resource.TestCheckResourceAttr("tfe_stack.foobar", "description", "Just an ordinary stack"),
105+
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "created_at"),
106+
resource.TestCheckResourceAttrSet("tfe_stack.foobar", "updated_at"),
107+
),
108+
},
109+
{
110+
ResourceName: "tfe_stack.foobar",
111+
ImportState: true,
112+
ImportStateVerify: true,
113+
},
114+
},
115+
})
116+
}
117+
118+
func testAccTFEStackResourceConfigWithAgentPool(orgName string) string {
119+
return fmt.Sprintf(`
120+
resource "tfe_organization" "foobar" {
121+
name = "%s"
122+
123+
}
124+
125+
resource "tfe_agent_pool" "foobar" {
126+
name = "agent-pool-test-example"
127+
organization = tfe_organization.foobar.name
128+
}
129+
130+
resource "tfe_project" "example" {
131+
name = "example"
132+
organization = tfe_organization.foobar.name
133+
}
134+
135+
resource "tfe_stack" "foobar" {
136+
name = "example-stack"
137+
description = "Just an ordinary stack"
138+
project_id = tfe_project.example.id
139+
agent_pool_id = tfe_agent_pool.foobar.id
140+
}
141+
`, orgName)
142+
}
143+
80144
func TestAccTFEStackResource_noVCSRepo(t *testing.T) {
81145
skipUnlessBeta(t)
82146

internal/provider/stack.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type modelTFEStackVCSRepo struct {
2323
type modelTFEStack struct {
2424
ID types.String `tfsdk:"id"`
2525
ProjectID types.String `tfsdk:"project_id"`
26+
AgentPoolID types.String `tfsdk:"agent_pool_id"`
2627
Name types.String `tfsdk:"name"`
2728
Description types.String `tfsdk:"description"`
2829
DeploymentNames types.Set `tfsdk:"deployment_names"`
@@ -42,6 +43,7 @@ func modelFromTFEStack(v *tfe.Stack) modelTFEStack {
4243
result := modelTFEStack{
4344
ID: types.StringValue(v.ID),
4445
ProjectID: types.StringValue(v.Project.ID),
46+
AgentPoolID: types.StringNull(),
4547
Name: types.StringValue(v.Name),
4648
Description: types.StringNull(),
4749
DeploymentNames: types.SetValueMust(types.StringType, names),
@@ -58,6 +60,10 @@ func modelFromTFEStack(v *tfe.Stack) modelTFEStack {
5860
}
5961
}
6062

63+
if v.AgentPool != nil {
64+
result.AgentPoolID = types.StringValue(v.AgentPool.ID)
65+
}
66+
6167
if v.Description != "" {
6268
result.Description = types.StringValue(v.Description)
6369
}

website/docs/r/stack.html.markdown

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ data "tfe_organization" "organization" {
2828
name = "my-example-org"
2929
}
3030
31+
data "tfe_agent_pool" "agent-pool" {
32+
name = "my-example-agent-pool"
33+
organization = tfe_organization.organization.name
34+
}
35+
3136
resource "tfe_stack" "test-stack" {
32-
name = "my-stack"
33-
description = "A Terraform Stack using two components with two environments"
34-
project_id = data.tfe_organization.organization.default_project_id
37+
name = "my-stack"
38+
description = "A Terraform Stack using two components with two environments"
39+
project_id = data.tfe_organization.organization.default_project_id
40+
agent_pool_id = data.tfe_agent_pool.agent-pool.id
3541
3642
vcs_repo {
3743
branch = "main"
@@ -70,6 +76,7 @@ The following arguments are supported:
7076

7177
* `name` - (Required) Name of the stack.
7278
* `project_id` - (Required) ID of the project where the stack should be created.
79+
* `agent_pool_id` - (Optional) The ID of an agent pool to assign to the stack.
7380
* `vcs_repo` - (Optional) Settings for the stack's VCS repository.
7481
* `description` - (Optional) Description of the stack
7582
<!--

0 commit comments

Comments
 (0)