-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tf
38 lines (36 loc) · 1.23 KB
/
main.tf
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
data "azurerm_client_config" "current" {
}
variable "domain" {}
variable "rg" {}
variable "location" {}
resource "azurerm_resource_group" "rg" {
name = var.rg
location = var.location
}
resource "null_resource" "b2c" {
triggers = {
subs = data.azurerm_client_config.current.subscription_id
rg = var.rg
domain = var.domain
}
provisioner "local-exec" {
command = <<EOF
export SUBS=${self.triggers.subs}
export RG=${self.triggers.rg}
export DOMAIN=${self.triggers.domain}
az rest --method put --url https://management.azure.com/subscriptions/$SUBS/resourceGroups/$RG/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$DOMAIN.onmicrosoft.com?api-version=2019-01-01-preview --body @b2c.json --verbose
EOF
}
provisioner "local-exec" {
when = destroy
command = <<EOF
export SUBS=${self.triggers.subs}
export RG=${self.triggers.rg}
export DOMAIN=${self.triggers.domain}
az rest --method delete --url https://management.azure.com/subscriptions/$SUBS/resourceGroups/$RG/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$DOMAIN.onmicrosoft.com?api-version=2019-01-01-preview --verbose
EOF
}
depends_on = [
azurerm_resource_group.rg
]
}