Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'auto_update' #690

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccAgentPool_DataSource(t *testing.T) {
resource.TestCheckResourceAttrSet(tfNode, "id"),
resource.TestCheckResourceAttr(tfNode, "name", agentPoolName),
resource.TestCheckResourceAttr(tfNode, "auto_provision", "false"),
resource.TestCheckResourceAttr(tfNode, "auto_update", "false"),
resource.TestCheckResourceAttr(tfNode, "pool_type", "automation"),
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAccAgentPool_CreateAndUpdate(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "name", poolNameFirst),
resource.TestCheckResourceAttr(tfNode, "auto_provision", "false"),
resource.TestCheckResourceAttr(tfNode, "auto_update", "false"),
resource.TestCheckResourceAttr(tfNode, "pool_type", "automation"),
checkAgentPoolExists(poolNameFirst),
),
Expand All @@ -49,6 +50,7 @@ func TestAccAgentPool_CreateAndUpdate(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "name", poolNameSecond),
resource.TestCheckResourceAttr(tfNode, "auto_provision", "false"),
resource.TestCheckResourceAttr(tfNode, "auto_update", "false"),
resource.TestCheckResourceAttr(tfNode, "pool_type", "automation"),
checkAgentPoolExists(poolNameSecond),
),
Expand Down
2 changes: 2 additions & 0 deletions azuredevops/internal/acceptancetests/testutils/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ func HclAgentPoolResource(poolName string) string {
resource "azuredevops_agent_pool" "pool" {
name = "%s"
auto_provision = false
auto_update = false
pool_type = "automation"
}`, poolName)
}
Expand All @@ -648,6 +649,7 @@ func HclAgentPoolResourceAppendPoolNameToResourceName(poolName string) string {
resource "azuredevops_agent_pool" "pool_%[1]s" {
name = "%[1]s"
auto_provision = false
auto_update = false
pool_type = "automation"
}`, poolName)
}
Expand Down
4 changes: 4 additions & 0 deletions azuredevops/internal/service/taskagent/data_agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func flattenAgentPoolReferences(input *[]taskagent.TaskAgentPool) []interface{}
output["auto_provision"] = *element.AutoProvision
}

if element.AutoUpdate != nil {
output["auto_update"] = *element.AutoUpdate
}

results = append(results, output)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,21 @@ var dataTestAgentPools = []taskagent.TaskAgentPool{
Name: converter.String("AgentPool"),
PoolType: &taskagent.TaskAgentPoolTypeValues.Automation,
AutoProvision: converter.Bool(false),
AutoUpdate: converter.Bool(false),
},
{
Id: converter.Int(65092),
Name: converter.String("AgentPool_AutoProvisioned"),
PoolType: &taskagent.TaskAgentPoolTypeValues.Automation,
AutoProvision: converter.Bool(true),
AutoUpdate: converter.Bool(true),
},
{
Id: converter.Int(650792),
Name: converter.String("AgentPool_Deployment"),
PoolType: &taskagent.TaskAgentPoolTypeValues.Deployment,
AutoProvision: converter.Bool(false),
AutoUpdate: converter.Bool(false),
},
}

Expand Down
19 changes: 19 additions & 0 deletions azuredevops/internal/service/taskagent/resource_agentpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func ResourceAgentPool() *schema.Resource {
Optional: true,
Default: false,
},
"auto_update": {
xuzhang3 marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
}
}
Expand All @@ -62,6 +67,14 @@ func resourceAzureAgentPoolCreate(d *schema.ResourceData, m interface{}) error {
return fmt.Errorf("Error creating agent pool in Azure DevOps: %+v", err)
}

if agentPool.AutoUpdate != nil && !*agentPool.AutoUpdate {
agentPool.Id = createdAgentPool.Id
createdAgentPool, err = azureAgentPoolUpdate(clients, agentPool)
if err != nil {
return fmt.Errorf("Error updating agent pool in Azure DevOps: %+v", err)
}
}

flattenAzureAgentPool(d, createdAgentPool)

return resourceAzureAgentPoolRead(d, m)
Expand Down Expand Up @@ -138,6 +151,7 @@ func azureAgentPoolUpdate(clients *client.AggregatedClient, agentPool *taskagent
Name: agentPool.Name,
PoolType: agentPool.PoolType,
AutoProvision: agentPool.AutoProvision,
AutoUpdate: agentPool.AutoUpdate,
},
})
}
Expand All @@ -147,6 +161,10 @@ func flattenAzureAgentPool(d *schema.ResourceData, agentPool *taskagent.TaskAgen
d.Set("name", converter.ToString(agentPool.Name, ""))
d.Set("pool_type", *agentPool.PoolType)
d.Set("auto_provision", *agentPool.AutoProvision)

if agentPool.AutoUpdate != nil {
d.Set("auto_update", *agentPool.AutoUpdate)
}
}

func expandAgentPool(d *schema.ResourceData, forCreate bool) (*taskagent.TaskAgentPool, error) {
Expand All @@ -162,6 +180,7 @@ func expandAgentPool(d *schema.ResourceData, forCreate bool) (*taskagent.TaskAge
Name: converter.String(d.Get("name").(string)),
PoolType: &poolType,
AutoProvision: converter.Bool(d.Get("auto_provision").(bool)),
AutoUpdate: converter.Bool(d.Get("auto_update").(bool)),
}

return pool, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestAgentPool_UpdateAgentPool_UpdateAndRead(t *testing.T) {
Name: converter.String("Foo"),
PoolType: &taskagent.TaskAgentPoolTypeValues.Deployment,
AutoProvision: converter.Bool(true),
AutoUpdate: converter.Bool(true),
}

resourceData := schema.TestResourceDataRaw(t, ResourceAgentPool().Schema, nil)
Expand All @@ -118,6 +119,7 @@ func TestAgentPool_UpdateAgentPool_UpdateAndRead(t *testing.T) {
Name: agentToUpdate.Name,
PoolType: agentToUpdate.PoolType,
AutoProvision: agentToUpdate.AutoProvision,
AutoUpdate: agentToUpdate.AutoUpdate,
},
}).
Return(&agentToUpdate, nil).
Expand All @@ -139,6 +141,7 @@ func TestAgentPool_UpdateAgentPool_UpdateAndRead(t *testing.T) {
require.Equal(t, agentToUpdate.Name, updatedTaskAgent.Name)
require.Equal(t, agentToUpdate.PoolType, updatedTaskAgent.PoolType)
require.Equal(t, agentToUpdate.AutoProvision, updatedTaskAgent.AutoProvision)
require.Equal(t, agentToUpdate.AutoUpdate, updatedTaskAgent.AutoUpdate)
}

// validates supported pool types are allowed by the schema
Expand Down
5 changes: 5 additions & 0 deletions website/docs/d/agent_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ output "pool_type" {
output "auto_provision" {
value = data.azuredevops_agent_pool.example.auto_provision
}

output "auto_update" {
value = data.azuredevops_agent_pool.example.auto_update
}
```

## Argument Reference
Expand All @@ -42,6 +46,7 @@ The following attributes are exported:
`name` - The name of the agent pool
`pool_type` - Specifies whether the agent pool type is Automation or Deployment.
`auto_provision` - Specifies whether a queue should be automatically provisioned for each project collection.
`auto_update` - Specifies whether or not agents within the pool should be automatically updated.

## Relevant Links

Expand Down
5 changes: 5 additions & 0 deletions website/docs/d/agent_pools.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ output "auto_provision" {
value = data.azuredevops_agent_pools.example.agent_pools.*.auto_provision
}

output "auto_update" {
value = data.azuredevops_agent_pools.example.agent_pools.*.auto_update
}

output "pool_type" {
value = data.azuredevops_agent_pools.example.agent_pools.*.pool_type
}
Expand All @@ -40,6 +44,7 @@ The following attributes are exported:
- `name` - The name of the agent pool
- `pool_type` - Specifies whether the agent pool type is Automation or Deployment.
- `auto_provision` - Specifies whether or not a queue should be automatically provisioned for each project collection.
- `auto_update` - Specifies whether or not agents within the pool should be automatically updated.

## Relevant Links

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/agent_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Manages an agent pool within Azure DevOps.
resource "azuredevops_agent_pool" "example" {
name = "Example-pool"
auto_provision = false
auto_update = false
}
```

Expand All @@ -25,6 +26,7 @@ The following arguments are supported:
- `name` - (Required) The name of the agent pool.
- `auto_provision` - (Optional) Specifies whether a queue should be automatically provisioned for each project collection. Defaults to `false`.
- `pool_type` - (Optional) Specifies whether the agent pool type is Automation or Deployment. Defaults to `automation`.
- `auto_update` - (Optional) Specifies whether or not agents within the pool should be automatically updated. Defaults to `true`.

## Attributes Reference

Expand Down