Skip to content

Commit bcadff7

Browse files
author
oleh_mykolaishyn
committed
fix: init version
1 parent 8df0ac2 commit bcadff7

File tree

5 files changed

+221
-1
lines changed

5 files changed

+221
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Azure <> Terraform module
1+
# Azure Container Intance Terraform module
22
Terraform module for creation Azure <>
33

44
## Usage

main.tf

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
resource "azurerm_container_group" "this" {
2+
name = var.container_instance_name
3+
location = var.location
4+
sku = var.sku
5+
os_type = var.os_type
6+
resource_group_name = var.resource_group_name
7+
restart_policy = var.restart_policy
8+
ip_address_type = var.ip_address_type
9+
subnet_ids = var.subnet_ids
10+
tags = var.tags
11+
12+
identity {
13+
type = var.identity_ids == null ? "SystemAssigned" : "SystemAssigned, UserAssigned"
14+
identity_ids = var.identity_ids
15+
}
16+
17+
dynamic "image_registry_credential" {
18+
for_each = var.image_registry_credential
19+
content {
20+
server = image_registry_credential.value.server
21+
username = image_registry_credential.value.username
22+
password = image_registry_credential.value.password
23+
}
24+
}
25+
26+
dynamic "container" {
27+
for_each = var.containers
28+
content {
29+
name = container.value.name
30+
cpu = container.value.cpu
31+
image = container.value.image
32+
memory = container.value.memory
33+
environment_variables = container.value.environment_variables
34+
35+
dynamic "ports" {
36+
for_each = container.value.ports_tcp
37+
content {
38+
port = ports.value
39+
protocol = "TCP"
40+
}
41+
}
42+
43+
dynamic "ports" {
44+
for_each = container.value.ports_udp
45+
content {
46+
port = ports.value
47+
protocol = "UDP"
48+
}
49+
}
50+
51+
dynamic "volume" {
52+
for_each = container.value.volumes
53+
content {
54+
name = volume.value.name
55+
mount_path = volume.value.mount_path
56+
storage_account_name = volume.value.storage_account_name
57+
storage_account_key = volume.value.storage_account_key
58+
share_name = volume.value.share_name
59+
}
60+
}
61+
}
62+
}
63+
64+
dynamic "exposed_port" {
65+
for_each = var.exposed_ports_tcp
66+
content {
67+
port = exposed_port.value
68+
protocol = "TCP"
69+
}
70+
}
71+
72+
dynamic "exposed_port" {
73+
for_each = var.exposed_ports_udp
74+
content {
75+
port = exposed_port.value
76+
protocol = "UDP"
77+
}
78+
}
79+
80+
dynamic "dns_config" {
81+
for_each = length(var.dns_config_nameservers) != 0 ? [1] : []
82+
content {
83+
nameservers = var.dns_config_nameservers
84+
}
85+
}
86+
}

outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "name" {
2+
value = azurerm_container_group.this.name
3+
description = "Name of the Azure Container Instance"
4+
}
5+
6+
output "id" {
7+
value = azurerm_container_group.this.id
8+
description = "Id of the Azure Container Instance"
9+
}
10+
11+
output "ip_address" {
12+
value = azurerm_container_group.this.ip_address
13+
description = "Public IP address of the Azure Container Instance"
14+
}
15+
16+
output "identity" {
17+
value = azurerm_container_group.this.identity[*]
18+
description = "List of identities assigned to the Azure Container Instance"
19+
}

variables.tf

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
variable "location" {
2+
type = string
3+
description = "Specifies the supported Azure location where the resource exists."
4+
}
5+
6+
variable "container_instance_name" {
7+
type = string
8+
description = "Specifies the name of the Container Group."
9+
}
10+
11+
variable "resource_group_name" {
12+
type = string
13+
description = "The name of the resource group in which to create the Container Group."
14+
}
15+
16+
variable "tags" {
17+
type = map(string)
18+
description = "Resource tags."
19+
default = {}
20+
}
21+
22+
variable "sku" {
23+
type = string
24+
description = "Specifies the sku of the Container Group. Possible values are Confidential, Dedicated and Standard. "
25+
default = "Standard"
26+
}
27+
28+
variable "os_type" {
29+
type = string
30+
description = "The OS for the container group. Allowed values are Linux and Windows."
31+
default = "Linux"
32+
}
33+
34+
variable "restart_policy" {
35+
type = string
36+
description = "Restart policy for the container group. Allowed values are Always, Never, OnFailure."
37+
default = "Never"
38+
}
39+
40+
variable "identity_ids" {
41+
type = list(string)
42+
description = "Specifies a list of User Assigned Managed Identity IDs to be assigned to this Container Group."
43+
default = null
44+
}
45+
46+
variable "ip_address_type" {
47+
type = string
48+
description = "Specifies the IP address type of the container. Public, Private or None."
49+
default = "Public"
50+
}
51+
52+
variable "subnet_ids" {
53+
type = list(string)
54+
description = "The subnet resource IDs for a container group."
55+
default = []
56+
}
57+
58+
variable "exposed_ports_tcp" {
59+
type = set(string)
60+
description = "Set of ports to expose with TCP protocol"
61+
default = []
62+
}
63+
64+
variable "exposed_ports_udp" {
65+
type = set(string)
66+
description = "Set of ports to expose with UDP protocol"
67+
default = []
68+
}
69+
70+
variable "image_registry_credential" {
71+
type = list(object({
72+
server = string
73+
username = string
74+
password = string
75+
}))
76+
description = "List of objects to configure connection to private registry"
77+
default = []
78+
}
79+
80+
variable "dns_config_nameservers" {
81+
type = list(string)
82+
description = "A list of nameservers the containers will search out to resolve requests. "
83+
default = []
84+
}
85+
86+
variable "containers" {
87+
type = list(object({
88+
name = string
89+
image = string
90+
cpu = number
91+
memory = number
92+
environment_variables = optional(map(string))
93+
commands = optional(list(string))
94+
ports_tcp = optional(set(string), [])
95+
ports_udp = optional(set(string), [])
96+
volumes = optional(list(object({
97+
mount_path = string
98+
name = string
99+
storage_account_name = optional(string)
100+
storage_account_key = optional(string)
101+
share_name = optional(string)
102+
})), [])
103+
}))
104+
description = "List of objects to configure containers"
105+
}

versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0.0"
3+
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm"
7+
version = ">= 3.68.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)