Excluding resource in Terraform module
up vote
1
down vote
favorite
I have a Terraform module which I built that deploys two instances of the module to a separate region. In this module there is a key vault. I only want the key vault to be present in one of the two regions.
Here is my module:
resource "azurerm_resource_group" "test" {
name = "test"
location = "${var.location}"
}
resource "azurerm_key_vault" "keyvault" {
name = "keyvault"
}
Here is my main.tf
module "test_uswest2" {
source = "modules/test"
location = "westus2"
environment = "${var.environment}"
}
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
}
I want to exclude the key vault in the second region/location.
Terraform doesn't seem to support if/else so I'm not sure what my options are.
terraform terraform-provider-azure
add a comment |
up vote
1
down vote
favorite
I have a Terraform module which I built that deploys two instances of the module to a separate region. In this module there is a key vault. I only want the key vault to be present in one of the two regions.
Here is my module:
resource "azurerm_resource_group" "test" {
name = "test"
location = "${var.location}"
}
resource "azurerm_key_vault" "keyvault" {
name = "keyvault"
}
Here is my main.tf
module "test_uswest2" {
source = "modules/test"
location = "westus2"
environment = "${var.environment}"
}
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
}
I want to exclude the key vault in the second region/location.
Terraform doesn't seem to support if/else so I'm not sure what my options are.
terraform terraform-provider-azure
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a Terraform module which I built that deploys two instances of the module to a separate region. In this module there is a key vault. I only want the key vault to be present in one of the two regions.
Here is my module:
resource "azurerm_resource_group" "test" {
name = "test"
location = "${var.location}"
}
resource "azurerm_key_vault" "keyvault" {
name = "keyvault"
}
Here is my main.tf
module "test_uswest2" {
source = "modules/test"
location = "westus2"
environment = "${var.environment}"
}
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
}
I want to exclude the key vault in the second region/location.
Terraform doesn't seem to support if/else so I'm not sure what my options are.
terraform terraform-provider-azure
I have a Terraform module which I built that deploys two instances of the module to a separate region. In this module there is a key vault. I only want the key vault to be present in one of the two regions.
Here is my module:
resource "azurerm_resource_group" "test" {
name = "test"
location = "${var.location}"
}
resource "azurerm_key_vault" "keyvault" {
name = "keyvault"
}
Here is my main.tf
module "test_uswest2" {
source = "modules/test"
location = "westus2"
environment = "${var.environment}"
}
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
}
I want to exclude the key vault in the second region/location.
Terraform doesn't seem to support if/else so I'm not sure what my options are.
terraform terraform-provider-azure
terraform terraform-provider-azure
edited Nov 8 at 9:18
ydaetskcoR
20.3k45372
20.3k45372
asked Nov 7 at 17:49
sleepyj
186
186
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
You can conditionally create resources by setting the count meta parameter to 0 and using the conditional ternary operator.
So you would have something like this:
variable "create_key_vault" {
default = true
}
resource "azurerm_key_vault" "keyvault" {
count = "${var.create_key_vault ? 0 : 1}"
name = "keyvault"
}
Then call your module with create_key_vault set to false to not create it:
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
create_key_vault = false
}
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
You can conditionally create resources by setting the count meta parameter to 0 and using the conditional ternary operator.
So you would have something like this:
variable "create_key_vault" {
default = true
}
resource "azurerm_key_vault" "keyvault" {
count = "${var.create_key_vault ? 0 : 1}"
name = "keyvault"
}
Then call your module with create_key_vault set to false to not create it:
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
create_key_vault = false
}
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
add a comment |
up vote
5
down vote
accepted
You can conditionally create resources by setting the count meta parameter to 0 and using the conditional ternary operator.
So you would have something like this:
variable "create_key_vault" {
default = true
}
resource "azurerm_key_vault" "keyvault" {
count = "${var.create_key_vault ? 0 : 1}"
name = "keyvault"
}
Then call your module with create_key_vault set to false to not create it:
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
create_key_vault = false
}
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
You can conditionally create resources by setting the count meta parameter to 0 and using the conditional ternary operator.
So you would have something like this:
variable "create_key_vault" {
default = true
}
resource "azurerm_key_vault" "keyvault" {
count = "${var.create_key_vault ? 0 : 1}"
name = "keyvault"
}
Then call your module with create_key_vault set to false to not create it:
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
create_key_vault = false
}
You can conditionally create resources by setting the count meta parameter to 0 and using the conditional ternary operator.
So you would have something like this:
variable "create_key_vault" {
default = true
}
resource "azurerm_key_vault" "keyvault" {
count = "${var.create_key_vault ? 0 : 1}"
name = "keyvault"
}
Then call your module with create_key_vault set to false to not create it:
module "test_westcentralus" {
source = "modules/test"
location = "centralus"
environment = "${var.environment}"
create_key_vault = false
}
edited Nov 8 at 18:08
answered Nov 7 at 19:19
ydaetskcoR
20.3k45372
20.3k45372
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
add a comment |
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
Just after posting this I realized the count. Thanks!
– sleepyj
Nov 14 at 16:09
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194995%2fexcluding-resource-in-terraform-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown