-
Notifications
You must be signed in to change notification settings - Fork 48
Add cloudstack_physicalnetwork
and some underlying additional resources
#201
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
- Implement data source for cloudstack_physicalnetwork to retrieve physical network details. - Create resource for managing cloudstack_physicalnetwork, including CRUD operations. - Add tests for both data source and resource functionalities. - Update documentation for cloudstack_physicalnetwork data source and resource.
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.
Pull Request Overview
This PR adds support for three new CloudStack resources that manage physical network infrastructure: cloudstack_physicalnetwork
, cloudstack_traffic_type
, and cloudstack_network_service_provider
. These resources allow Terraform to manage physical network configurations in CloudStack zones.
- Implements complete CRUD operations for physical networks, traffic types, and network service providers
- Adds corresponding data source for querying physical networks
- Includes comprehensive test coverage for all new resources
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
cloudstack/provider.go | Registers new resources and data source with provider |
cloudstack/resource_cloudstack_physicalnetwork.go | Physical network resource implementation |
cloudstack/resource_cloudstack_traffic_type.go | Traffic type resource implementation |
cloudstack/resource_cloudstack_network_service_provider.go | Network service provider resource implementation |
cloudstack/data_source_cloudstack_physicalnetwork.go | Physical network data source implementation |
website/docs/r/*.html.markdown | Documentation for new resources |
website/docs/d/physicalnetwork.html.markdown | Documentation for new data source |
*_test.go files | Test suites for all new resources and data source |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if d.Get("kvm_network_label") == "" { | ||
d.Set("kvm_network_label", "cloudbr0") | ||
} | ||
|
||
if d.Get("xen_network_label") == "" { | ||
d.Set("xen_network_label", "xenbr0") | ||
} | ||
|
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.
Setting default values during import can cause configuration drift. These hardcoded defaults may not match the actual CloudStack configuration and will cause Terraform to detect changes on subsequent plans. Consider removing these default assignments or making them optional.
if d.Get("kvm_network_label") == "" { | |
d.Set("kvm_network_label", "cloudbr0") | |
} | |
if d.Get("xen_network_label") == "" { | |
d.Set("xen_network_label", "xenbr0") | |
} | |
// Do not set hardcoded defaults for kvm_network_label or xen_network_label during import. | |
// If the API provides these values, set them; otherwise, leave them unset. |
Copilot uses AI. Check for mistakes.
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.
@ianc769 , I think we can considder this co-pilot comment in a future improvement. the magic values here are a bit ugly and rigid (albeit correct)
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 manually the resources
network_service_provider,
cloudstack_physicalnetwork,
cloudstack_traffic_type
Also the data_source_cloudstack_physicalnetwork
resource "cloudstack_zone" "foo" {
name = "terraform-zone"
dns1 = "8.8.8.8"
internal_dns1 = "8.8.4.4"
network_type = "Advanced"
}
resource "cloudstack_physicalnetwork" "foo" {
name = "terraform-physical-network"
zone = cloudstack_zone.foo.name
broadcast_domain_range = "ZONE"
isolation_methods = ["VLAN"]
}
resource "cloudstack_traffic_type" "foo" {
physical_network_id = cloudstack_physicalnetwork.foo.id
type = "Management"
kvm_network_label = "cloudbr0"
}
resource "cloudstack_network_service_provider" "securitygroup" {
name = "SecurityGroupProvider"
physical_network_id = cloudstack_physicalnetwork.foo.id
state = "Enabled"
}
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_service_provider.securitygroup will be created
+ resource "cloudstack_network_service_provider" "securitygroup" {
+ id = (known after apply)
+ name = "SecurityGroupProvider"
+ physical_network_id = (known after apply)
+ state = "Enabled"
}
# cloudstack_physicalnetwork.foo will be created
+ resource "cloudstack_physicalnetwork" "foo" {
+ broadcast_domain_range = "ZONE"
+ id = (known after apply)
+ isolation_methods = [
+ "VLAN",
]
+ name = "terraform-physical-network"
+ zone = "terraform-zone"
}
# cloudstack_traffic_type.foo will be created
+ resource "cloudstack_traffic_type" "foo" {
+ id = (known after apply)
+ kvm_network_label = "cloudbr0"
+ physical_network_id = (known after apply)
+ type = "Management"
}
# cloudstack_zone.foo will be created
+ resource "cloudstack_zone" "foo" {
+ dns1 = "8.8.8.8"
+ id = (known after apply)
+ internal_dns1 = "8.8.4.4"
+ name = "terraform-zone"
+ network_type = "Advanced"
}
Plan: 4 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_zone.foo: Creating...
cloudstack_zone.foo: Creation complete after 1s [id=760d4c0d-cc59-4245-bb30-18d3448ae672]
cloudstack_physicalnetwork.foo: Creating...
cloudstack_physicalnetwork.foo: Creation complete after 1s [id=318ce63d-7642-4174-8f3e-69b00f38c98a]
cloudstack_network_service_provider.securitygroup: Creating...
cloudstack_traffic_type.foo: Creating...
cloudstack_network_service_provider.securitygroup: Creation complete after 1s [id=8cebfeed-7df8-444a-9802-6d9a86dd4de8]
cloudstack_traffic_type.foo: Creation complete after 1s [id=abcb7c9f-05f6-4ff1-a90f-3b16394cef1e]
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.
╭─ ~/Desktop/cloudstack-India-demo/cloudstack-terraform copy ✔ ╱ 5s ╱ Azure subscription 1 ╱ 03:52:39 PM
╰─ terraform destroy
cloudstack_zone.foo: Refreshing state... [id=760d4c0d-cc59-4245-bb30-18d3448ae672]
cloudstack_physicalnetwork.foo: Refreshing state... [id=318ce63d-7642-4174-8f3e-69b00f38c98a]
cloudstack_network_service_provider.securitygroup: Refreshing state... [id=8cebfeed-7df8-444a-9802-6d9a86dd4de8]
cloudstack_traffic_type.foo: Refreshing state... [id=abcb7c9f-05f6-4ff1-a90f-3b16394cef1e]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# cloudstack_network_service_provider.securitygroup will be destroyed
- resource "cloudstack_network_service_provider" "securitygroup" {
- id = "8cebfeed-7df8-444a-9802-6d9a86dd4de8" -> null
- name = "SecurityGroupProvider" -> null
- physical_network_id = "318ce63d-7642-4174-8f3e-69b00f38c98a" -> null
- state = "Enabled" -> null
}
# cloudstack_physicalnetwork.foo will be destroyed
- resource "cloudstack_physicalnetwork" "foo" {
- broadcast_domain_range = "ZONE" -> null
- id = "318ce63d-7642-4174-8f3e-69b00f38c98a" -> null
- isolation_methods = [
- "VLAN",
] -> null
- name = "terraform-physical-network" -> null
- zone = "terraform-zone" -> null
# (2 unchanged attributes hidden)
}
# cloudstack_traffic_type.foo will be destroyed
- resource "cloudstack_traffic_type" "foo" {
- id = "abcb7c9f-05f6-4ff1-a90f-3b16394cef1e" -> null
- kvm_network_label = "cloudbr0" -> null
- physical_network_id = "318ce63d-7642-4174-8f3e-69b00f38c98a" -> null
- type = "Management" -> null
}
# cloudstack_zone.foo will be destroyed
- resource "cloudstack_zone" "foo" {
- dns1 = "8.8.8.8" -> null
- id = "760d4c0d-cc59-4245-bb30-18d3448ae672" -> null
- internal_dns1 = "8.8.4.4" -> null
- name = "terraform-zone" -> null
- network_type = "Advanced" -> null
}
Plan: 0 to add, 0 to change, 4 to destroy.
Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
cloudstack_network_service_provider.securitygroup: Destroying... [id=8cebfeed-7df8-444a-9802-6d9a86dd4de8]
cloudstack_traffic_type.foo: Destroying... [id=abcb7c9f-05f6-4ff1-a90f-3b16394cef1e]
cloudstack_traffic_type.foo: Destruction complete after 1s
cloudstack_network_service_provider.securitygroup: Destruction complete after 1s
cloudstack_physicalnetwork.foo: Destroying... [id=318ce63d-7642-4174-8f3e-69b00f38c98a]
cloudstack_physicalnetwork.foo: Destruction complete after 0s
cloudstack_zone.foo: Destroying... [id=760d4c0d-cc59-4245-bb30-18d3448ae672]
cloudstack_zone.foo: Destruction complete after 0s
Destroy complete! Resources: 4 destroyed.
data "cloudstack_physicalnetwork" "default" {
filter {
name = "name"
value = "terraform-physical-network"
}
}
output "zome" {
value = data.cloudstack_physicalnetwork.default.zone
}
terraform apply
data.cloudstack_physicalnetwork.default: Reading...
data.cloudstack_physicalnetwork.default: Read complete after 0s [id=7f434f12-dece-4705-b08f-980d97fc542d]
Changes to Outputs:
+ zome = "terraform-zone"
You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
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
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
zome = "terraform-zone"

Adding
cloudstack_physicalnetwork
,cloudstack_traffic_type
andcloudstack_physicalnetwork
as terraform managed resource options:cloudstack_physicalnetwork
-> https://cloudstack.apache.org/api/apidocs-4.20/apis/createPhysicalNetwork.htmlcloudstack_traffic_type
-> https://cloudstack.apache.org/api/apidocs-4.20/apis/addTrafficType.htmlcloudstack_network_service_provider
-> https://cloudstack.apache.org/api/apidocs-4.20/apis/addNetworkServiceProvider.htmlUsing this code for example: