Terraform: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
|||
Linha 1: | Linha 1: | ||
=IF Statement= | =IF Statement= | ||
I want an module in terraform which is able to execute two different codes. <br> | I want an module in terraform which is able to execute two different codes. <br> | ||
Linha 45: | Linha 46: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==AND== | ==AND== | ||
{|class=wikitable align="center" | {|class=wikitable align="center" | ||
!foo | !foo | ||
Linha 87: | Linha 88: | ||
count = "${signum(var.foo + var.bar)}" | count = "${signum(var.foo + var.bar)}" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Links= | |||
*[https://www.terraform.io/docs/configuration-0-11/interpolation.html Interpolation Syntax] | |||
*[https://stackoverflow.com/questions/39479849/is-there-a-way-and-or-conditional-operator-in-terraform Source here] |
Edição das 16h27min de 15 de julho de 2019
IF Statement
I want an module in terraform which is able to execute two different codes.
One with a image from a Publisher and other with a custom image.
Codes above show how to specify both operations in the same module:
module "virtualmachine" {
source = "git@github.com:accountname/git.git///path?ref=xxxxxxxx"
vm_name = "virtualmachine"
location = "East US 2"
vm_image_reference = "no"
image_publisher = "MicrosoftSQLServer"
image_offer = "SQL2016SP1-WS2016"
image_sku = "Enterprise"
image_version = "latest"
vm_size = "Standard_DS11_v2"
vm_disk_type = "Premium_LRS"
vm_data_disks = ["1023"]
}
module "virtualmachine" {
source = "git@github.com:accountname/git.git///path?ref=xxxxxxxx"
vm_name = "virtualmachine"
location = "East US 2"
vm_image_reference = "yes"
vm_image = "/subscriptions/xxxxxxxxxxxxx/resourceGroups/Images/providers/Microsoft.Compute/images/centos_720201230"
vm_size = "Standard_DS11_v2"
vm_disk_type = "Premium_LRS"
vm_data_disks = ["1023"]
}
resource "azurerm_virtual_machine" "image" {
count = "${format("%.1s", var.vm_image_reference) == "y" ? 1 : 0}"
.
.
.
}
resource "azurerm_virtual_machine" "market" {
count = "${format("%.1s", var.vm_image_reference) == "n" ? 1 : 0}"
.
.
.
}
AND
foo | bar | result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 1 | 1 |
OR
count = "${var.foo * var.bar}"
foo | bar | result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 1 | 1 |
count = "${signum(var.foo + var.bar)}"