Compare commits

..

1 Commits

Author SHA1 Message Date
3d918001e7 Initial put 2024-10-14 13:56:33 -07:00
8 changed files with 49 additions and 132 deletions

View File

@ -1,26 +0,0 @@
# Azure Container Group
This template deploys an Azure Container Group with two containers.
## Terraform resource types
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [azurerm_container_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group)
## Variables
| Name | Description | Default value |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
| `container_group_name` | Name of the container group resource. | "" |
| `image_registry_credential_1_server` | Server name for the first image registry credential. | "" |
| `image_registry_credential_1_username` | Username for the first image registry credential. | "" |
| `image_registry_credential_1_password` | Password for the first image registry credential. | "" |
| `image_registry_credential_2_server` | Server name for the second image registry credential. | "" |
| `image_registry_credential_2_username` | Username for the second image registry credential. | "" |
| `image_registry_credential_2_password` | Password for the second image registry credential. | "" |
## Example

View File

@ -1,31 +0,0 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "container_group_name" {
value = azurerm_container_group.example.name
}
output "container_group_ip_address" {
value = azurerm_container_group.example.ip_address
}
output "container_group_os_type" {
value = azurerm_container_group.example.os_type
}
output "container_group_image_registry_credential_1_server" {
value = azurerm_container_group.example.image_registry_credential[0].server
}
output "container_group_image_registry_credential_2_server" {
value = azurerm_container_group.example.image_registry_credential[1].server
}
output "container_group_container_1_name" {
value = azurerm_container_group.example.container[0].name
}
output "container_group_container_2_name" {
value = azurerm_container_group.example.container[1].name
}

View File

@ -1,53 +0,0 @@
variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}
variable "container_group_name" {
type = string
description = "The name of the container group resource. The value will be randomly generated if blank."
default = ""
}
variable "image_registry_credential_1_server" {
type = string
description = "Server name for the first image registry credential."
default = ""
}
variable "image_registry_credential_1_username" {
type = string
description = "Username for the first image registry credential."
default = ""
}
variable "image_registry_credential_1_password" {
type = string
description = "Password for the first image registry credential."
default = ""
}
variable "image_registry_credential_2_server" {
type = string
description = "Server name for the second image registry credential."
default = ""
}
variable "image_registry_credential_2_username" {
type = string
description = "Username for the second image registry credential."
default = ""
}
variable "image_registry_credential_2_password" {
type = string
description = "Password for the second image registry credential."
default = ""
}

View File

@ -0,0 +1,18 @@
# Azure Container Group
This template deploys an Azure Container Group with two containers.
## Terraform resource types
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [azurerm_container_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group)
## Variables
| Name | Description | Default |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
## Example

View File

@ -7,33 +7,18 @@ resource "azurerm_resource_group" "rg" {
name = random_pet.rg_name.id
}
resource "random_string" "azurerm_container_group_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
resource "random_pet" "azurerm_container_group_name" {
prefix = "cont"
}
resource "azurerm_container_group" "example" {
name = coalesce(var.container_group_name, "cg-${random_string.azurerm_container_group_name.result}")
resource_group_name = azurerm_resource_group.rg.name
name = "${random_pet.azurerm_container_group_name.id}-examplecont"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
ip_address_type = "Public"
dns_name_label = "${random_pet.azurerm_container_group_name.id}-examplecont"
os_type = "Linux"
image_registry_credential {
server = var.image_registry_credential_1_server
username = var.image_registry_credential_1_username
password = var.image_registry_credential_1_password
}
image_registry_credential {
server = var.image_registry_credential_2_server
username = var.image_registry_credential_2_username
password = var.image_registry_credential_2_password
}
container {
name = "hw"
image = "mcr.microsoft.com/azuredocs/aci-helloworld:latest"

View File

@ -0,0 +1,15 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "container_group_name" {
value = azurerm_container_group.example.name
}
output "ip_address" {
value = azurerm_container_group.example.ip_address
}
output "fqdn" {
value = azurerm_container_group.example.fqdn
}

View File

@ -1,6 +1,5 @@
terraform {
required_version = ">=1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
@ -12,7 +11,6 @@ terraform {
}
}
}
provider "azurerm" {
features {}
}

View File

@ -0,0 +1,11 @@
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}
variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}