Skip to content

Commit 8e4e90b

Browse files
committed
agent pool support for stack resource
1 parent 190945a commit 8e4e90b

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

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 time when the stack was last updated.",
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,63 @@ resource "tfe_stack" "foobar" {
7777
`, orgName, ghToken, ghRepoIdentifier)
7878
}
7979

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

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
}

0 commit comments

Comments
 (0)