Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSG have issue with count, for_each or dynamic block will help .. #3

Open
tutorialbyexample opened this issue Jun 22, 2020 · 0 comments

Comments

@tutorialbyexample
Copy link

Thanks for this post, however, I found issues while considering production implementation, as while using count in any resource or module, that resource getting destroy and create again once we are doing any addition or change in between resource as index position getting changed and due to that all other resource destroying and creating again. for example lets see if we want to create 4 NSGs and its created with index
nsgs = merge(
var.nsg_db,
var.nsg_app,
var.test,
var.test1
)

module.oci_security_policies.oci_core_network_security_group.this[0], module.oci_security_policies.oci_core_network_security_group.this[1]
module.oci_security_policies.oci_core_network_security_group.this[2]
module.oci_security_policies.oci_core_network_security_group.this[3]

Later due to any issue if we remove one items form var.test, then all other will recreate due to index position changes and all other application need to updated with newly created nsg ocid.

nsgs = merge(
var.nsg_db,
var.nsg_app,
var.test,
var.test1
)

resource definitions

resource "oci_core_network_security_group" "this" {
count = length(local.nsgs_keys)
compartment_id = var.nsgs[local.nsgs_keys[count.index]].compartment_id != null ? var.nsgs[local.nsgs_keys[count.index]].compartment_id : var.default_compartment_id
vcn_id = var.vcn_id
display_name = local.nsgs_keys[count.index] != null ? local.nsgs_keys[count.index] : "${local.default_nsgs_opt.display_name}-${count.index}"
defined_tags = var.nsgs[local.nsgs_keys[count.index]].defined_tags != null ? var.nsgs[local.nsgs_keys[count.index]].defined_tags : var.default_defined_tags
freeform_tags = var.nsgs[local.nsgs_keys[count.index]].freeform_tags != null ? var.nsgs[local.nsgs_keys[count.index]].freeform_tags : var.default_freeform_tags
}

Either dynamic block or for_each will help, please assist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant