-
Notifications
You must be signed in to change notification settings - Fork 55
Deprecate usage of ports (port list) and add support to use updateNetworkAclItems API instead of recreating rules when modified #242
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Tested with port and rule_number able to create and update
resource "cloudstack_network_acl_rule" "test" {
acl_id = "b70ac793-4bf1-434d-a75d-baf7e959a1c8"
rule {
rule_number = 16
action = "allow"
cidr_list = ["10.0.0.0/24"]
protocol = "tcp"
port = "81-83"
traffic_type = "ingress"
description = "testing terraform ACL issue-new-1"
}
rule {
rule_number = 17
action = "allow"
cidr_list = ["10.0.0.0/24"]
protocol = "tcp"
port = "2222-2223"
traffic_type = "ingress"
description = "testing terraform ACL issue - 2dsg"
}
rule {
rule_number = 18
action = "allow"
cidr_list = ["10.0.0.0/24"]
protocol = "tcp"
port = "8081"
traffic_type = "ingress"
description = "testing terraform ACL issue - 2"
}
rule {
rule_number = 19
action = "allow"
cidr_list = ["10.0.0.0/24"]
protocol = "tcp"
port = "8086"
traffic_type = "Egress"
description = "testing terraform ACL issue - 3"
}
}
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# cloudstack_network_acl_rule.default will be created
+ resource "cloudstack_network_acl_rule" "default" {
+ acl_id = "8ad13c5a-700f-467b-ad79-70fd942d3a09"
+ id = (known after apply)
+ managed = false
+ parallelism = 2
+ rule {
+ action = "allow"
+ cidr_list = [
+ "10.0.0.0/24",
]
+ description = "testing terraform ACL issue"
+ icmp_code = (known after apply)
+ icmp_type = (known after apply)
+ port = "80-81"
+ protocol = "tcp"
+ rule_number = 16
+ traffic_type = "ingress"
+ uuids = (known after apply)
}
+ rule {
+ action = "allow"
+ cidr_list = [
+ "10.0.0.0/24",
]
+ description = "testing terraform ACL issue - 1"
+ icmp_code = (known after apply)
+ icmp_type = (known after apply)
+ port = "2222-2223"
+ protocol = "tcp"
+ rule_number = 17
+ traffic_type = "ingress"
+ uuids = (known after apply)
}
+ rule {
+ action = "allow"
+ cidr_list = [
+ "10.0.0.0/24",
]
+ description = "testing terraform ACL issue - 2"
+ icmp_code = (known after apply)
+ icmp_type = (known after apply)
+ port = "8080"
+ protocol = "tcp"
+ rule_number = 18
+ traffic_type = "ingress"
+ uuids = (known after apply)
}
+ rule {
+ action = "allow"
+ cidr_list = [
+ "10.0.0.0/24",
]
+ description = "testing terraform ACL issue - 3"
+ icmp_code = (known after apply)
+ icmp_type = (known after apply)
+ port = "8081"
+ protocol = "tcp"
+ rule_number = 19
+ traffic_type = "ingress"
+ uuids = (known after apply)
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_network_acl_rule.default: Creating...
cloudstack_network_acl_rule.default: Creation complete after 3s [id=8ad13c5a-700f-467b-ad79-70fd942d3a09]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
╭─ ~/Desktop/cloudstack-India-demo/cloudstack-terraform-copy ✔ ╱ 4s ╱ Azure subscription 1 ╱ 10:50:58 AM
╰─ terraform apply
cloudstack_network_acl_rule.default: Refreshing state... [id=8ad13c5a-700f-467b-ad79-70fd942d3a09]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# cloudstack_network_acl_rule.default will be updated in-place
~ resource "cloudstack_network_acl_rule" "default" {
id = "8ad13c5a-700f-467b-ad79-70fd942d3a09"
# (3 unchanged attributes hidden)
~ rule {
~ port = "80-81" -> "80-82"
# (10 unchanged attributes hidden)
}
~ rule {
~ port = "2222-2223" -> "2222-2225"
# (10 unchanged attributes hidden)
}
~ rule {
~ protocol = "tcp" -> "udp"
# (10 unchanged attributes hidden)
}
~ rule {
~ description = "testing terraform ACL issue - 3" -> "testing terraform ACL issue - 4"
# (10 unchanged attributes hidden)
}
}
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_network_acl_rule.default: Modifying... [id=8ad13c5a-700f-467b-ad79-70fd942d3a09]
cloudstack_network_acl_rule.default: Modifications complete after 4s [id=8ad13c5a-700f-467b-ad79-70fd942d3a09]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
When ports is mentioned in the terraform config , warning and exception is thrown
Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Warning: Argument is deprecated
│
│ with cloudstack_network_acl_rule.default,
│ on main.tf line 18, in resource "cloudstack_network_acl_rule" "default":
│ 18: ports = ["80", "1000-2000"]
│
│ Use 'port' instead. The 'ports' field is deprecated and will be removed in a future version.
│
│ (and 5 more similar warnings elsewhere)
╵
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_network_acl_rule.default: Creating...
╷
│ Warning: Argument is deprecated
│
│ with cloudstack_network_acl_rule.default,
│ on main.tf line 18, in resource "cloudstack_network_acl_rule" "default":
│ 18: ports = ["80", "1000-2000"]
│
│ Use 'port' instead. The 'ports' field is deprecated and will be removed in a future version.
│
│ (and 2 more similar warnings elsewhere)
╵
╷
│ Error: 3 errors occurred:
│ * rule #1: The 'ports' field is deprecated. Use 'port' instead for new configurations.
│ * rule #2: The 'ports' field is deprecated. Use 'port' instead for new configurations.
│ * rule #3: The 'ports' field is deprecated. Use 'port' instead for new configurations.
│
│
│
│ with cloudstack_network_acl_rule.default,
│ on main.tf line 10, in resource "cloudstack_network_acl_rule" "default":
│ 10: resource "cloudstack_network_acl_rule" "default" {
|
@Pearl1594 can you update the documentation to use port |
DaanHoogland
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clgtm generally
| return err | ||
| } | ||
|
|
||
| // Create all rules that are configured |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CodeBleu , this is an example of what I meant earlier. The comment above can be the name of a method that contains the if-else block below. That would make it easier to read and maintain. Again, this is not due to this PR but changing it would make the code more readable.
|
I've addressed your comments @DaanHoogland . Thanks. |
|
@Pearl1594 I'm having issues with using rule numbers. │ I using My rules don't match, and even when I run plan again, it shows UPDATE This is prob going to be an issue for users when they use the new provider and it detects these changes and doesn't apply them correctly initially and have to delete all their rules and re-apply I tried to just change the description on one of the rules and it shows this: It applies, but it never updated my rule If I create a new rule and don't give it a Then I change description ( notice not rule_number above was not specified ) OpenTofu will perform the following actions: and after apply
|
|
@Pearl1594 After further testing it appears that updating the Description on rule I deleted all my rules again and created them all with no I then tested on the next 2 or 3 rules after 1 and they all work and update in CS like they are supposed to. |
|
@Pearl1594 I decided to change a The
|
|
Let me check these @CodeBleu. Thanks for reporting. |
|
@CodeBleu I was testing you observation, by first creating ACL rules using the previous version 0.5.0 After moving to the latest release, now 0.6.0-rc3, we first would have to delete the ports as you mentioned and then re-add the rules using port. This was done because we cannot use This resulted in the following order in ACS At this point, in the terraform.tfstate file the rule_numbers for all rules except 443 is 0 (here is where the issue lies, as the read function isn't storing the rule number in the state) however since 443 had the rule_number explicitly set in the config, it gets updated, which is why went I on to change the rule number of the ACL rule for port 80-81 (which is currently 1) to 7, and it identified the change as 0 -> 7 , which is what you observed as well. And the resultant list of ACL rules on ACS looks like:
So yes, there seems to be an issue, but do you think it's a blocker? I believe if all acl rules have rule number set we can work around the issue observed. |
The fact that the TF will change the wrong Also, did you see my other issues ( |
|
I wasn't able to reproduce the issue where in the rule isn't updated though the plan indicates otherwise. It would be great if you could help verify if the PR addresses the rule number issue. Thanks |
I have tested and left my results on #245 |




This PR attempts to deprecate the usage of "ports" with the introduction of "rule_number" support in the 0.6.0 release.
Caution has been taken to allow backward compatibility for delete operation. However creation of new config and update is disallowed if ports is used. Users will be prompted to migrate to use port parameter.