-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
112 lines (89 loc) · 2.44 KB
/
main.tf
File metadata and controls
112 lines (89 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4.0.0"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
required_version = ">= 0.14.9"
}
provider "docker" {
host = "npipe:////./pipe/dockerDesktopLinuxEngine"
}
provider "azurerm" {
subscription_id = "azuresubid"
features {
}
}
# Generate a random integer to create a globally unique name
resource "random_integer" "ri" {
min = 10000
max = 99999
}
resource "azurerm_resource_group" "rg" {
name = "per-dojo"
location = "North Europe"
}
// doesn't use docker hub anymore, instead pulls from the images in the resource group's private image registry
resource "azurerm_container_registry" "acr" {
name = "PerDojoContainerRegistry"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
sku = "Basic"
admin_enabled = true
}
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_image" "apiimage" {
name = "notesapp"
build {
context = "."
tag = ["${azurerm_container_registry.acr.login_server}/notesapp:dev"]
dockerfile = "./Dockerfile"
build_arg = {
environment : "dev"
}
label = {
author : "perlh"
}
}
}
resource "null_resource" "docker_push" {
provisioner "local-exec" {
command = <<-EOT
docker push "${azurerm_container_registry.acr.login_server}/notesapp:dev"
EOT
}
depends_on = [
docker_image.apiimage
]
}
resource "azurerm_container_app_environment" "contappenv" {
name = "container-app-env"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_container_app" "example" {
name = "notesappcontainerapp"
container_app_environment_id = azurerm_container_app_environment.contappenv.id
resource_group_name = azurerm_resource_group.rg.name
revision_mode = "Single"
template {
container {
name = "noteaspp"
image = "${azurerm_container_registry.acr.login_server}/notesapp:dev"
cpu = 0.25
memory = "0.5Gi"
}
}
// image should be pushed and available in acr before container is made
depends_on = [
null_resource.docker_push
]
}