Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- provider "azurerm" {
- version = "=1.44.0"
- }
- # where to locate our infrastructure
- variable "location" {
- type = string
- default = "northeurope"
- }
- # the name of our docker image
- variable "mockapp_docker_image" {
- type = string
- default = "mockapp:latest"
- }
- # random string for resources names.
- resource "random_string" "random" {
- length = 10
- special = false
- upper = false
- lower = true
- }
- # our resource group
- resource "azurerm_resource_group" "main" {
- name = "DockerResourceGroup"
- location = var.location
- }
- # ======================================================================================
- # Mock app container
- # ======================================================================================
- resource "azurerm_container_registry" "container_registry" {
- name = "${substr(uuid(), 1, 5)}containerregistry"
- resource_group_name = azurerm_resource_group.main.name
- location = azurerm_resource_group.main.location
- sku = "Basic"
- admin_enabled = true
- # build & push image
- provisioner "local-exec" {
- command = "az acr build --image ${var.mockapp_docker_image} --registry ${self.name} ."
- }
- }
- resource "azurerm_container_group" "container_group" {
- name = "${random_string.random.result}-container-group"
- location = azurerm_resource_group.main.location
- resource_group_name = azurerm_resource_group.main.name
- ip_address_type = "public"
- dns_name_label = "${random_string.random.result}-mockapp"
- os_type = "Linux"
- image_registry_credential {
- server = "${azurerm_container_registry.container_registry.name}.azurecr.io"
- username = azurerm_container_registry.container_registry.admin_username
- password = azurerm_container_registry.container_registry.admin_password
- }
- container {
- name = "mockapp"
- image = "${azurerm_container_registry.container_registry.name}.azurecr.io/${var.mockapp_docker_image}"
- cpu = "1"
- memory = "1"
- ports {
- port = 80
- protocol = "TCP"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement