Skip to content

Commit ee0944d

Browse files
authored
Merge pull request #1 from data-platform-hq/vmss-pool
feat: vmss pool
2 parents d21883f + 6595e4f commit ee0944d

File tree

5 files changed

+202
-3
lines changed

5 files changed

+202
-3
lines changed

README.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,84 @@
1-
# Azure <> Terraform module
2-
Terraform module for creation Azure <>
1+
# Azure Devops VMSS Elastic Pool Terraform module
2+
Terraform module for creation Azure Devops VMSS Elastic Pool
33

44
## Usage
5+
```hcl
6+
data "azurerm_subnet" "example" {
7+
name = "example-name"
8+
virtual_network_name = "example-vnet-name"
9+
resource_group_name = "example-rg"
10+
}
511
12+
module "ado_vmss_agent_pool" {
13+
source = "data-platform-hq/vmss-pool/azuredevops"
14+
version = "~> 1.0"
15+
16+
vm_scale_set_name = "example-vm-scale-set"
17+
location = "eastus"
18+
resource_group = "example-rg"
19+
subnet_id = data.azurerm_subnet.example.id
20+
ado_project_name = "datahq"
21+
ado_service_connection_azurerm_name = "example-ado-service-connection-name"
22+
ado_vmss_pool_name = "example-ado-vmss-pool-name"
23+
}
24+
```
625
<!-- BEGIN_TF_DOCS -->
26+
## Requirements
27+
28+
| Name | Version |
29+
| ---------------------------------------------------------------------------- | --------- |
30+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
31+
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 3.75.0 |
32+
| <a name="requirement_azuredevops"></a> [azuredevops](#requirement\_azuredevops) | >= 0.10.0 |
33+
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4.0.5 |
34+
35+
## Providers
36+
37+
| Name | Version |
38+
| ---------------------------------------------------------------------- | ------- |
39+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.75.0 |
40+
| <a name="requirement_azuredevops"></a> [azuredevops](#requirement\_azuredevops) | >= 0.10.0 |
41+
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4.0.5 |
42+
43+
## Modules
44+
45+
| Module | Path | Version |
46+
|--------------------------------------------------------------------|--------------------------------|---------|
47+
| [vmss](https://github.com/data-platform-hq/terraform-azurerm-vmss) | data-platform-hq/vmss/azurerm | 1.1.0 |
48+
49+
## Resources
50+
51+
| Name | Type |
52+
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
53+
| [tls_private_key.this](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
54+
| [azuredevops_project.this](https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/data-sources/project) | data |
55+
| [azuredevops_serviceendpoint_azurerm.this](https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/data-sources/serviceendpoint_azurerm) | data |
56+
| [azuredevops_elastic_pool.this](https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/elastic_pool) | resource |
57+
| [azuredevops_agent_queue.this](https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/agent_queue) | resource |
58+
| [azuredevops_pipeline_authorization.this](https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/pipeline_authorization) resource |
59+
60+
## Inputs
61+
62+
| Name | Description | Type | Default | Required |
63+
|------|-------------|------|-------------------------------------------------------------------------------------------------------------------------------------------------------|:--------:|
64+
| <a name="input_vm_scale_set_name"></a> [vm\_scale\_set\_name](#input\_vm\_scale\_set\_name)| VM Scale Sets name | `string` | n/a | yes |
65+
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group)| The name of the resource group. | `string` | n/a| yes |
66+
| <a name="input_location"></a> [location](#input\_location)| The Azure Region in which all resources in this example should be created. | `string` | n/a | yes |
67+
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id)| Subnet where VM Scale Sets would be provisioned | `string` | n/a | yes |
68+
| <a name="input_ado_project_name"></a> [ado\_project\_name](#input\_ado\_project\_name)| Target Azure DevOps Project name where VMSS agent pool would be provisioned | `string` | n/a | yes |
69+
| <a name="input_ado_service_connection_azurerm_name"></a> [ado\_service\_connection\_azurerm\_name](#input\_ado\_service\_connection\_azurerm\_name)| Name of existing Azure DevOps Service Connection AzureRM that points to Azure Subscription with VMSS used in agent pool | `string` | n/a | yes |
70+
| <a name="input_ado_vmss_pool_name"></a> [ado\_vmss\_pool\_name](#input\_ado\_vmss\_pool\_name)| Given name to Azure DevOps VMSS agent pool | `string` | n/a | yes |
71+
| <a name="input_ado_vmss_pool_configuration"></a> [ado\_vmss\_pool\_configuration](#input\_ado\_vmss\_pool\_configuration)| Object with configuration options for Azure DevOps VMSS agent pool | <pre>object({<br> desired_idle = optional(number)<br> max_capacity = optional(number)<br> time_to_live_minutes = optional(number)<br> recycle_after_each_use = optional(bool)<br>})</pre> |<pre>object({<br> desired_idle = optional(number, 0)<br> max_capacity = optional(number, 3)<br> time_to_live_minutes = optional(number, 30)<br> recycle_after_each_use = optional(bool, false)<br>})</pre> | no |
72+
73+
## Outputs
74+
75+
| Name | Description |
76+
| ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
77+
| <a name="output_vmss_id"></a> [vmss\_id](#output\_vmss\_id) | VM Scale Sets id |
78+
| <a name="output_public_ip_prefix"></a> [public\_ip\_prefix](#output\_public\_ip\_prefix) | Public IP Address Prefix CIDR |
779

880
<!-- END_TF_DOCS -->
981

1082
## License
1183

12-
Apache 2 Licensed. For more information please see [LICENSE](https://github.com/data-platform-hq/terraform-azurerm<>/tree/master/LICENSE)
84+
Apache 2 Licensed. For more information please see [LICENSE](https://github.com/data-platform-hq/terraform-azuredevops-vmss-pool/tree/master/LICENSE)

main.tf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
resource "tls_private_key" "this" {
2+
algorithm = "RSA"
3+
rsa_bits = 2048
4+
}
5+
6+
module "vmss" {
7+
source = "data-platform-hq/vmss/azurerm"
8+
version = "1.1.0"
9+
10+
scale_set_name = var.vm_scale_set_name
11+
location = var.location
12+
resource_group = var.resource_group
13+
admin_ssh_key = { public_key = tls_private_key.this.public_key_openssh }
14+
subnet = var.subnet_id
15+
extensions = [{
16+
name = "packages"
17+
publisher = "Microsoft.Azure.Extensions"
18+
type = "CustomScript"
19+
type_handler_version = "2.0"
20+
settings = jsonencode({
21+
"script" : (base64encode("apt-get update -y && apt-get upgrade -y; apt-get -y install unzip"))
22+
})
23+
}]
24+
}
25+
26+
data "azuredevops_project" "this" {
27+
name = var.ado_project_name
28+
}
29+
30+
data "azuredevops_serviceendpoint_azurerm" "this" {
31+
project_id = data.azuredevops_project.this.id
32+
service_endpoint_name = var.ado_service_connection_azurerm_name
33+
}
34+
35+
resource "azuredevops_elastic_pool" "this" {
36+
name = var.ado_vmss_pool_name
37+
service_endpoint_id = data.azuredevops_serviceendpoint_azurerm.this.id
38+
service_endpoint_scope = data.azuredevops_project.this.id
39+
azure_resource_id = module.vmss.id
40+
desired_idle = var.ado_vmss_pool_configuration.desired_idle
41+
max_capacity = var.ado_vmss_pool_configuration.max_capacity
42+
time_to_live_minutes = var.ado_vmss_pool_configuration.time_to_live_minutes
43+
recycle_after_each_use = var.ado_vmss_pool_configuration.recycle_after_each_use
44+
}
45+
46+
resource "azuredevops_agent_queue" "this" {
47+
project_id = data.azuredevops_project.this.id
48+
agent_pool_id = azuredevops_elastic_pool.this.id
49+
}
50+
51+
resource "azuredevops_pipeline_authorization" "this" {
52+
project_id = data.azuredevops_project.this.id
53+
resource_id = azuredevops_agent_queue.this.id
54+
type = "queue"
55+
}

outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "vmss_id" {
2+
value = module.vmss.id
3+
description = "VM Scale Sets id"
4+
}
5+
6+
output "public_ip_prefix" {
7+
value = module.vmss.public_ips
8+
description = "Public IP Address Prefix CIDR"
9+
}

variables.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
variable "vm_scale_set_name" {
2+
description = "VM Scale Sets name"
3+
type = string
4+
}
5+
6+
variable "resource_group" {
7+
description = "The name of the resource group."
8+
type = string
9+
}
10+
11+
variable "location" {
12+
description = "The Azure Region in which all resources in this example should be created."
13+
type = string
14+
}
15+
16+
variable "subnet_id" {
17+
description = "Subnet where VM Scale Sets would be provisioned"
18+
type = string
19+
}
20+
21+
variable "ado_project_name" {
22+
description = "Target Azure DevOps Project name where VMSS agent pool would be provisioned"
23+
type = string
24+
}
25+
26+
variable "ado_service_connection_azurerm_name" {
27+
description = "Name of existing Azure DevOps Service Connection AzureRM that points to Azure Subscription with VMSS used in agent pool"
28+
type = string
29+
}
30+
31+
variable "ado_vmss_pool_name" {
32+
description = "Given name to Azure DevOps VMSS agent pool"
33+
type = string
34+
}
35+
36+
variable "ado_vmss_pool_configuration" {
37+
description = "Object with configuration options for Azure DevOps VMSS agent pool"
38+
type = object({
39+
desired_idle = optional(number, 0)
40+
max_capacity = optional(number, 3)
41+
time_to_live_minutes = optional(number, 30)
42+
recycle_after_each_use = optional(bool, false)
43+
})
44+
default = {}
45+
}

versions.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_version = ">= 1.0.0"
3+
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm"
7+
version = ">= 3.75.0"
8+
}
9+
azuredevops = {
10+
source = "microsoft/azuredevops"
11+
version = ">= 0.10.0"
12+
}
13+
tls = {
14+
source = "hashicorp/tls"
15+
version = ">= 4.0.5"
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)