Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. provider "azurerm" {
  2. version = "=1.44.0"
  3. }
  4.  
  5. # where to locate our infrastructure
  6. variable "location" {
  7. type = string
  8. default = "northeurope"
  9. }
  10.  
  11. # the name of our docker image
  12. variable "mockapp_docker_image" {
  13. type = string
  14. default = "mockapp:latest"
  15. }
  16.  
  17. # random string for resources names.
  18. resource "random_string" "random" {
  19. length = 10
  20. special = false
  21. upper = false
  22. lower = true
  23. }
  24.  
  25. # our resource group
  26.  
  27. resource "azurerm_resource_group" "main" {
  28. name = "DockerResourceGroup"
  29. location = var.location
  30. }
  31.  
  32. # ======================================================================================
  33. # Mock app container
  34. # ======================================================================================
  35.  
  36. resource "azurerm_container_registry" "container_registry" {
  37. name = "${substr(uuid(), 1, 5)}containerregistry"
  38. resource_group_name = azurerm_resource_group.main.name
  39. location = azurerm_resource_group.main.location
  40. sku = "Basic"
  41. admin_enabled = true
  42.  
  43. # build & push image
  44. provisioner "local-exec" {
  45. command = "az acr build --image ${var.mockapp_docker_image} --registry ${self.name} ."
  46. }
  47. }
  48.  
  49. resource "azurerm_container_group" "container_group" {
  50.  
  51. name = "${random_string.random.result}-container-group"
  52. location = azurerm_resource_group.main.location
  53. resource_group_name = azurerm_resource_group.main.name
  54. ip_address_type = "public"
  55. dns_name_label = "${random_string.random.result}-mockapp"
  56. os_type = "Linux"
  57.  
  58. image_registry_credential {
  59. server = "${azurerm_container_registry.container_registry.name}.azurecr.io"
  60. username = azurerm_container_registry.container_registry.admin_username
  61. password = azurerm_container_registry.container_registry.admin_password
  62. }
  63.  
  64. container {
  65. name = "mockapp"
  66. image = "${azurerm_container_registry.container_registry.name}.azurecr.io/${var.mockapp_docker_image}"
  67. cpu = "1"
  68. memory = "1"
  69.  
  70. ports {
  71. port = 80
  72. protocol = "TCP"
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement