New sample (converted from Bicep via OpenAI)
This commit is contained in:
parent
c4d4d696a5
commit
47483432a8
36
quickstart/101-aci-linuxcontainer-public-ip/main.tf
Normal file
36
quickstart/101-aci-linuxcontainer-public-ip/main.tf
Normal file
@ -0,0 +1,36 @@
|
||||
resource "random_pet" "rg_name" {
|
||||
prefix = var.resource_group_name_prefix
|
||||
}
|
||||
|
||||
resource "azurerm_resource_group" "rg" {
|
||||
name = random_pet.rg_name.id
|
||||
location = var.resource_group_location
|
||||
}
|
||||
|
||||
resource "random_string" "container_name" {
|
||||
length = 25
|
||||
lower = true
|
||||
upper = false
|
||||
special = false
|
||||
}
|
||||
|
||||
resource "azurerm_container_group" "container" {
|
||||
name = "${var.container_group_name_prefix}-${random_string.container_name.result}"
|
||||
location = azurerm_resource_group.rg.location
|
||||
resource_group_name = azurerm_resource_group.rg.name
|
||||
ip_address_type = "Public"
|
||||
os_type = "Linux"
|
||||
restart_policy = var.restart_policy
|
||||
|
||||
container {
|
||||
name = "${var.container_name_prefix}-${random_string.container_name.result}"
|
||||
image = var.image
|
||||
cpu = var.cpu_cores
|
||||
memory = var.memory_in_gb
|
||||
|
||||
ports {
|
||||
port = var.port
|
||||
protocol = "TCP"
|
||||
}
|
||||
}
|
||||
}
|
3
quickstart/101-aci-linuxcontainer-public-ip/outputs.tf
Normal file
3
quickstart/101-aci-linuxcontainer-public-ip/outputs.tf
Normal file
@ -0,0 +1,3 @@
|
||||
output "container_ipv4_address" {
|
||||
value = azurerm_container_group.container.ip_address
|
||||
}
|
16
quickstart/101-aci-linuxcontainer-public-ip/providers.tf
Normal file
16
quickstart/101-aci-linuxcontainer-public-ip/providers.tf
Normal file
@ -0,0 +1,16 @@
|
||||
terraform {
|
||||
required_version = ">=1.0"
|
||||
required_providers {
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
version = "~>3.4"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "~>3.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
26
quickstart/101-aci-linuxcontainer-public-ip/readme.md
Normal file
26
quickstart/101-aci-linuxcontainer-public-ip/readme.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Azure Container Instance with public IP
|
||||
|
||||
This template deploys an Azure Container Instance with a public IP address.
|
||||
|
||||
## 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 |
|
||||
| `name` | Name for the container group | acilinuxpublicipcontainergroup |
|
||||
| `image` | Container image to deploy. | mcr.microsoft.com/azuredocs/aci-helloworld" |
|
||||
| `port` | Port to open on the container and the public IP address. | 80 |
|
||||
| `cpu_cores` | Quantity of CPU cores to allocate to the container. | 1 |
|
||||
| `memory_in_gb` | Amount of memory to allocate to the container in gigabytes. | 2 |
|
||||
| `restart_policy` | Behavior of Azure runtime if container has stopped. | Always |
|
||||
|
||||
## Example
|
||||
|
||||
To see how to run this example, see [Create an Azure resource group using Terraform](https://docs.microsoft.com/azure/developer/terraform/create-resource-group).
|
57
quickstart/101-aci-linuxcontainer-public-ip/variables.tf
Normal file
57
quickstart/101-aci-linuxcontainer-public-ip/variables.tf
Normal file
@ -0,0 +1,57 @@
|
||||
variable "resource_group_location" {
|
||||
type = string
|
||||
default = "eastus"
|
||||
description = "Location for all resources."
|
||||
}
|
||||
|
||||
variable "resource_group_name_prefix" {
|
||||
type = string
|
||||
default = "rg"
|
||||
description = "Prefix of the resource group name that's combined with a random value so name is unique in your Azure subscription."
|
||||
}
|
||||
|
||||
variable "container_group_name_prefix" {
|
||||
type = string
|
||||
description = "Prefix of the container group name that's combined with a random value so name is unique in your Azure subscription."
|
||||
default = "acigroup"
|
||||
}
|
||||
|
||||
variable "container_name_prefix" {
|
||||
type = string
|
||||
description = "Prefix of the container name that's combined with a random value so name is unique in your Azure subscription."
|
||||
default = "aci"
|
||||
}
|
||||
|
||||
variable "image" {
|
||||
type = string
|
||||
description = "Container image to deploy. Should be of the form repoName/imagename:tag for images stored in public Docker Hub, or a fully qualified URI for other registries. Images from private registries require additional registry credentials."
|
||||
default = "mcr.microsoft.com/azuredocs/aci-helloworld"
|
||||
}
|
||||
|
||||
variable "port" {
|
||||
type = number
|
||||
description = "Port to open on the container and the public IP address."
|
||||
default = 80
|
||||
}
|
||||
|
||||
variable "cpu_cores" {
|
||||
type = number
|
||||
description = "The number of CPU cores to allocate to the container."
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "memory_in_gb" {
|
||||
type = number
|
||||
description = "The amount of memory to allocate to the container in gigabytes."
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "restart_policy" {
|
||||
type = string
|
||||
description = "The behavior of Azure runtime if container has stopped."
|
||||
default = "Always"
|
||||
validation {
|
||||
condition = contains(["Always", "Never", "OnFailure"], var.restart_policy)
|
||||
error_message = "The restart_policy must be one of the following: Always, Never, OnFailure."
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user