Skip to content

Commit

Permalink
Merge branch 'main' into grept-apply-1722734789
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredfholgate authored Aug 4, 2024
2 parents b3c7dfd + 8099ea6 commit f2b6f7e
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 57 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ The following resources are used by this module:
- [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
- [modtm_telemetry.telemetry](https://registry.terraform.io/providers/azure/modtm/latest/docs/resources/telemetry) (resource)
- [random_uuid.telemetry](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/uuid) (resource)
- [time_offset.placeholder_job](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/offset) (resource)
- [time_sleep.delay_after_container_image_build](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) (resource)
- [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) (data source)
- [azurerm_client_config.telemetry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) (data source)
Expand Down Expand Up @@ -261,14 +260,6 @@ Type: `number`

Default: `300`

### <a name="input_container_app_placeholder_schedule_offset_minutes"></a> [container\_app\_placeholder\_schedule\_offset\_minutes](#input\_container\_app\_placeholder\_schedule\_offset\_minutes)

Description: The offset in minutes for the placeholder job.

Type: `number`

Default: `5`

### <a name="input_container_app_polling_interval_seconds"></a> [container\_app\_polling\_interval\_seconds](#input\_container\_app\_polling\_interval\_seconds)

Description: How often should the pipeline queue be checked for new events, in seconds.
Expand Down Expand Up @@ -853,6 +844,14 @@ Type: `string`

Default: `null`

### <a name="input_version_control_system_placeholder_agent_name"></a> [version\_control\_system\_placeholder\_agent\_name](#input\_version\_control\_system\_placeholder\_agent\_name)

Description: The version control system placeholder agent name.

Type: `string`

Default: `null`

### <a name="input_version_control_system_pool_name"></a> [version\_control\_system\_pool\_name](#input\_version\_control\_system\_pool\_name)

Description: The name of the agent pool in the version control system.
Expand Down
1 change: 1 addition & 0 deletions examples/azure_devops_container_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ module "azure_devops_agents" {
version_control_system_pool_name = azuredevops_agent_pool.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}
output "container_instance_resource_ids" {
Expand Down
1 change: 1 addition & 0 deletions examples/azure_devops_container_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ module "azure_devops_agents" {
version_control_system_pool_name = azuredevops_agent_pool.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}

output "container_instance_resource_ids" {
Expand Down
1 change: 1 addition & 0 deletions examples/azure_devops_public_networking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ module "azure_devops_agents" {
version_control_system_pool_name = azuredevops_agent_pool.this.name
use_private_networking = false
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}
output "container_app_environment_resource_id" {
Expand Down
1 change: 1 addition & 0 deletions examples/azure_devops_public_networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module "azure_devops_agents" {
version_control_system_pool_name = azuredevops_agent_pool.this.name
use_private_networking = false
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}

output "container_app_environment_resource_id" {
Expand Down
1 change: 1 addition & 0 deletions examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ module "azure_devops_agents" {
version_control_system_pool_name = azuredevops_agent_pool.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}
output "container_app_environment_resource_id" {
Expand Down
1 change: 1 addition & 0 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module "azure_devops_agents" {
version_control_system_pool_name = azuredevops_agent_pool.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}

output "container_app_environment_resource_id" {
Expand Down
1 change: 1 addition & 0 deletions examples/github_basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ module "github_runners" {
version_control_system_repository = github_repository.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [github_repository_file.this]
}
# Region helpers
Expand Down
1 change: 1 addition & 0 deletions examples/github_basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module "github_runners" {
version_control_system_repository = github_repository.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [github_repository_file.this]
}

# Region helpers
Expand Down
1 change: 1 addition & 0 deletions examples/github_container_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module "github_runners" {
version_control_system_repository = github_repository.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [github_repository_file.this]
}
# Region helpers
Expand Down
1 change: 1 addition & 0 deletions examples/github_container_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module "github_runners" {
version_control_system_repository = github_repository.this.name
virtual_network_address_space = "10.0.0.0/16"
tags = local.tags
depends_on = [github_repository_file.this]
}

# Region helpers
Expand Down
1 change: 1 addition & 0 deletions examples/github_public_networking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ module "github_runners" {
version_control_system_repository = github_repository.this.name
use_private_networking = false
tags = local.tags
depends_on = [github_repository_file.this]
}
# Region helpers
Expand Down
1 change: 1 addition & 0 deletions examples/github_public_networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module "github_runners" {
version_control_system_repository = github_repository.this.name
use_private_networking = false
tags = local.tags
depends_on = [github_repository_file.this]
}

# Region helpers
Expand Down
2 changes: 2 additions & 0 deletions examples/multi_region/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ module "azure_devops_agents_primary" {
virtual_network_address_space = "10.0.0.0/16"
container_app_polling_interval_seconds = local.primary_polling_interval_prime_number
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}
module "azure_devops_agents_secondary" {
Expand All @@ -166,6 +167,7 @@ module "azure_devops_agents_secondary" {
virtual_network_address_space = "10.1.0.0/16"
container_app_polling_interval_seconds = local.secondary_polling_interval_prime_number
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}
output "primary_region" {
Expand Down
2 changes: 2 additions & 0 deletions examples/multi_region/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ module "azure_devops_agents_primary" {
virtual_network_address_space = "10.0.0.0/16"
container_app_polling_interval_seconds = local.primary_polling_interval_prime_number
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}

module "azure_devops_agents_secondary" {
Expand All @@ -158,6 +159,7 @@ module "azure_devops_agents_secondary" {
virtual_network_address_space = "10.1.0.0/16"
container_app_polling_interval_seconds = local.secondary_polling_interval_prime_number
tags = local.tags
depends_on = [azuredevops_pipeline_authorization.this]
}

output "primary_region" {
Expand Down
8 changes: 4 additions & 4 deletions locals.container.app.job.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ locals {
locals {
environment_variables_placeholder = tolist(jsondecode(local.environment_variables_placeholder_final))
environment_variables_placeholder_azure_devops = [
{
name = "AZP_AGENT_NAME"
value = local.version_control_system_placeholder_agent_name
},
{
name = "AZP_PLACEHOLDER"
value = "true"
Expand Down Expand Up @@ -96,7 +100,3 @@ locals {
}
]
}

locals {
cron_expression = local.deploy_container_app ? "${time_offset.placeholder_job[0].minute} ${time_offset.placeholder_job[0].hour} ${time_offset.placeholder_job[0].day} ${time_offset.placeholder_job[0].month} *" : ""
}
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
user_assigned_managed_identity_id = var.user_assigned_managed_identity_id != null ? var.user_assigned_managed_identity_id : module.user_assigned_managed_identity[0].resource_id
user_assigned_managed_identity_name = var.user_assigned_managed_identity_name != null ? var.user_assigned_managed_identity_name : "uami-${var.postfix}"
version_control_system_agent_name_prefix = var.version_control_system_agent_name_prefix != null ? var.version_control_system_agent_name_prefix : (var.version_control_system_type == local.version_control_system_azure_devops ? "agent-${var.postfix}" : "runner-${var.postfix}")
version_control_system_placeholder_agent_name = var.version_control_system_placeholder_agent_name != null ? var.version_control_system_placeholder_agent_name : "placeholder-${var.postfix}"
virtual_network_name = var.virtual_network_name != null ? var.virtual_network_name : "vnet-${var.postfix}"
}

Expand Down
19 changes: 1 addition & 18 deletions main.container.app.job.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
resource "time_offset" "placeholder_job" {
count = local.deploy_container_app ? 1 : 0

offset_minutes = var.container_app_placeholder_schedule_offset_minutes
triggers = {
container_image = local.container_images["container_app"].image_names[0]
offset_minutes = var.container_app_placeholder_schedule_offset_minutes
environment_variables = jsonencode(local.environment_variables)
sensitive_environment_variables = jsonencode(local.sensitive_environment_variables)
environment_variables_placeholder = jsonencode(local.environment_variables_placeholder)
image_version = var.default_image_repository_commit
}

depends_on = [module.container_registry, azurerm_container_app_environment.this, time_sleep.delay_after_container_image_build]
}

module "container_app_job" {
count = local.deploy_container_app ? 1 : 0
source = "./modules/container-app-job"
Expand Down Expand Up @@ -45,7 +29,6 @@ module "container_app_job" {
placeholder_container_name = var.container_app_placeholder_container_name
placeholder_replica_retry_limit = var.container_app_placeholder_replica_retry_limit
placeholder_replica_timeout = var.container_app_placeholder_replica_timeout
placeholder_cron_expression = local.cron_expression

polling_interval_seconds = var.container_app_polling_interval_seconds
container_cpu = var.container_app_container_cpu
Expand All @@ -57,4 +40,4 @@ module "container_app_job" {
user_assigned_managed_identity_id = local.user_assigned_managed_identity_id

depends_on = [module.container_registry, azurerm_private_dns_zone_virtual_network_link.container_registry, time_sleep.delay_after_container_image_build]
}
}
27 changes: 16 additions & 11 deletions modules/container-app-job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ resource "azapi_resource" "placeholder" {
replicaRetryLimit = var.placeholder_replica_retry_limit
replicaTimeout = var.placeholder_replica_timeout
registries = local.container_registies
scheduleTriggerConfig = {
cronExpression = var.placeholder_cron_expression
manualTriggerConfig = {
parallelism = 1
replicaCompletionCount = 1
}
secrets = local.secrets
triggerType = "Schedule"
triggerType = "Manual"
}
template = {
containers = [local.container_placeholder]
Expand All @@ -76,6 +75,19 @@ resource "azapi_resource" "placeholder" {
identity_ids = [var.user_assigned_managed_identity_id]
}
}
resource "azapi_resource_action" "placeholder_trigger" {
count = var.placeholder_job_creation_enabled ? 1 : 0
resource_id = azapi_resource.placeholder[0].id
type = "Microsoft.App/jobs@2024-03-01"
action = "start"
body = {}
lifecycle {
replace_triggered_by = [azapi_resource.placeholder]
}
}
```

<!-- markdownlint-disable MD033 -->
Expand All @@ -99,6 +111,7 @@ The following resources are used by this module:

- [azapi_resource.job](https://registry.terraform.io/providers/azure/azapi/latest/docs/resources/resource) (resource)
- [azapi_resource.placeholder](https://registry.terraform.io/providers/azure/azapi/latest/docs/resources/resource) (resource)
- [azapi_resource_action.placeholder_trigger](https://registry.terraform.io/providers/azure/azapi/latest/docs/resources/resource_action) (resource)

<!-- markdownlint-disable MD013 -->
## Required Inputs
Expand Down Expand Up @@ -268,14 +281,6 @@ Type: `string`

Default: `null`

### <a name="input_placeholder_cron_expression"></a> [placeholder\_cron\_expression](#input\_placeholder\_cron\_expression)

Description: The cron expression for the placeholder Container Apps job.

Type: `string`

Default: `null`

### <a name="input_placeholder_job_creation_enabled"></a> [placeholder\_job\_creation\_enabled](#input\_placeholder\_job\_creation\_enabled)

Description: Whether or not to create a placeholder job.
Expand Down
18 changes: 15 additions & 3 deletions modules/container-app-job/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ resource "azapi_resource" "placeholder" {
replicaRetryLimit = var.placeholder_replica_retry_limit
replicaTimeout = var.placeholder_replica_timeout
registries = local.container_registies
scheduleTriggerConfig = {
cronExpression = var.placeholder_cron_expression
manualTriggerConfig = {
parallelism = 1
replicaCompletionCount = 1
}
secrets = local.secrets
triggerType = "Schedule"
triggerType = "Manual"
}
template = {
containers = [local.container_placeholder]
Expand All @@ -70,3 +69,16 @@ resource "azapi_resource" "placeholder" {
identity_ids = [var.user_assigned_managed_identity_id]
}
}

resource "azapi_resource_action" "placeholder_trigger" {
count = var.placeholder_job_creation_enabled ? 1 : 0

resource_id = azapi_resource.placeholder[0].id
type = "Microsoft.App/jobs@2024-03-01"
action = "start"
body = {}

lifecycle {
replace_triggered_by = [azapi_resource.placeholder]
}
}
6 changes: 0 additions & 6 deletions modules/container-app-job/variables.placeholder.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,3 @@ variable "placeholder_replica_timeout" {
description = "The timeout in seconds for the placeholder Container Apps job."
default = 300
}

variable "placeholder_cron_expression" {
type = string
description = "The cron expression for the placeholder Container Apps job."
default = null
}
6 changes: 0 additions & 6 deletions variables.container.app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,3 @@ variable "container_app_infrastructure_resource_group_name" {
default = null
description = "The name of the resource group where the Container Apps infrastructure is deployed."
}

variable "container_app_placeholder_schedule_offset_minutes" {
type = number
default = 5
description = "The offset in minutes for the placeholder job."
}
6 changes: 6 additions & 0 deletions variables.version.control.system.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ variable "version_control_system_agent_name_prefix" {
description = "The version control system agent name prefix."
}

variable "version_control_system_placeholder_agent_name" {
type = string
default = null
description = "The version control system placeholder agent name."
}

variable "version_control_system_agent_target_queue_length" {
type = number
default = 1
Expand Down

0 comments on commit f2b6f7e

Please sign in to comment.