-
Notifications
You must be signed in to change notification settings - Fork 85
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
Importing T1 information failing on VMC-NSX-T #1043
Comments
Hi @chanakanissanka,
This only happens when the object you are importing is already in the terraform.tfstate file, which means it was created or already imported by the provider. The step for importing a resource from NSX is
I think one way to fix the situation is to go to the terraform.tfstate file, find the resource name mgw_policy and remove it from state. Once it's removed you should be able to import it with terraform import command. Please let me know if it works. |
@2ez4szliu Thanks for the quick reply, right after I opened this case and tried again and finally make it happen, Import successful! The resources that were imported are shown above. These resources are now in Thanks for that, |
@chanakanissanka I would suggest creating several policy sections for your distributed firewall, each contains no more than 1000 rules because the maximum number of rules in one policy supported by nsxt provider is 1000. |
Importing those rules into the state seems to be messy and hairy. Is there any other way to refer to pre-created rules, like a resource? resource "nsxt_policy_predefined_security_policy" "test" { tag { rule { rule { default_rule { } |
Hi @chanakanissanka,
Do you mean a resource for managing all DFW rules? From the template you provided seems you are creating a
and then create security policy like this:
Is this what you are asking for? |
a correction to the above comment: I don't think we can first create the rule then use it in security policy template to create the policy because we cannot create the rule without the policy, but I understand that you want a separate resource to refer to the rules in a policy. If you only want to refer to a specific rule, I think a data source for DFW rule might be able to do that. |
@2ez4szliu thanks for the reploy so far mate, |
@chanakanissanka I think these rules are already aware by the state once you have imported the policy with terraform, you can view its state by you can create data source like: Shizhao |
Hi There, thanks again } } |
Hi @chanakanissanka sorry for the confusion, this data source is currently not supported by nsxt provider. I just want to check with you if this would sufficient for you to managing your rule before we start to implement it. |
@2ez4szliu I see. That will be ok since we not gonna update all rules at once, wonder normally how log will it take to have this feature ? |
We can include this feature in the next release v3.4.1, which is currently due on Jan 11 2024 according to the milestone v3.4.1 https://github.com/vmware/terraform-provider-nsxt/milestone/1 |
@2ez4szliu appreciate these details. Just to summarise what we discussed, |
@chanakanissanka The above is correct, I will let you know if anything changes |
@2ez4szliu One last thing to clarify
|
For 1. As long as these policies and rules are successfully created on NSX side then we can import them into terraform |
@2ez4szliu, you are right, and we managed to successfully import a few of those policy sets rules into the state, now the state is messy (with so many rules ) and needs to find a way to update this into code so the plan will not make noise. |
Describe the bug
Hi There,
We have pre-created T1’s, the CGW and the MGW. They are pre-created with some default rules to allow outbound internet access. These rules need to be imported into our Terraform code. We are getting import errors and appreciate some help on resolving those.
Reproduction steps
resource "nsxt_policy_gateway_policy" "mgw_policy" {
category = "LocalGatewayRules"
display_name = "default"
domain = "mgw"
}
CGW definition
resource "nsxt_policy_gateway_policy" "cgw_policy" {
category = "LocalGatewayRules"
display_name = "default"
domain = "cgw"
}
terraform import nsxt_policy_gateway_policy.cgw_policy cgw/default
terraform import nsxt_policy_gateway_policy.mgw_policy mgw/default
3.Getting the error bellow due to the resource we created above. Can we get some help here ? what am I missing here ?
sxt_policy_gateway_policy.cgw_policy: Import prepared!
Prepared nsxt_policy_gateway_policy for import
data.nsxt_policy_security_policy.predefined: Read complete after 0s [id=default-layer3-section]
╷
│ Error: Resource already managed by Terraform
│
│ Terraform is already managing a remote object for nsxt_policy_gateway_policy.cgw_policy. To import to this address you must first remove the existing object from the state.
...
Expected behavior
Import to be ok and I can get those into my tf state file
Additional context
No response
The text was updated successfully, but these errors were encountered: