Traffic Types not handled correctly
I tried to import traffic types into terraform, but they all got imported as "Management".
The problem is that it looks for 'name', which doesn't exist, so it always defaults to Management. The API returns 'traffictype'.
This appears to be an issue also /w the upstream cloudstack go library, and even the freaking API documentation. 🤪
Here is what I get when I do the request via cloudmonkey, and I confirmed I got the same results from CloudStack python package.
{
"count": 4,
"traffictype": [
{
"id": "b20ba0e0-5c8c-4cb7-ab68-8fe3e011a336",
"physicalnetworkid": "ad0e9614-6d9c-41c8-9459-7539673b2107",
"traffictype": "Guest"
},
{
"id": "9f2b4227-653c-4523-b848-4dc889e2c8ff",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "ad0e9614-6d9c-41c8-9459-7539673b2107",
"traffictype": "Management"
},
{
"id": "5de01b4b-1448-4ee6-af4c-529a50966527",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "ad0e9614-6d9c-41c8-9459-7539673b2107",
"traffictype": "Public"
},
{
"id": "52c4901f-467c-414d-9cdd-534a0fb8195e",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "ad0e9614-6d9c-41c8-9459-7539673b2107",
"traffictype": "Storage"
}
]
}
@ilsaloving-gander I am unable to reproduce the issue
resource "cloudstack_traffic_type" "management" {
physical_network_id = "79213e81-1498-45f6-ae02-02524c3b9831"
type = "Management"
kvm_network_label = "cloudbr0"
xen_network_label = "xenbr0"
vmware_network_label = "VM Network"
}
Get the traffic type id from cmk
(localcloud) 🐱 > list traffictypes physicalnetworkid=79213e81-1498-45f6-ae02-02524c3b9831
{
"count": 2,
"traffictype": [
{
"id": "d952bc43-214d-4df6-addb-b055d2a842b2",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "79213e81-1498-45f6-ae02-02524c3b9831",
"traffictype": "Management",
"vmwarenetworklabel": "vSwitch0,,vmwaresvs",
"xennetworklabel": "Network0"
},
{
"id": "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "79213e81-1498-45f6-ae02-02524c3b9831",
"traffictype": "Storage",
"vmwarenetworklabel": "vSwitch0,,vmwaresvs",
"xennetworklabel": "Network0"
}
]
}
TF_LOG=DEBUG terraform import cloudstack_traffic_type.management "d952bc43-214d-4df6-addb-b055d2a842b2"
2025-10-17T18:35:52.189+0530 [INFO] Terraform version: 1.12.1
2025-10-17T18:35:52.189+0530 [DEBUG] using github.com/hashicorp/go-tfe v1.74.1
2025-10-17T18:35:52.189+0530 [DEBUG] using github.com/hashicorp/hcl/v2 v2.23.1-0.20250203194505-ba0759438da2
2025-10-17T18:35:52.190+0530 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2025-10-17T18:35:52.190+0530 [DEBUG] using github.com/zclconf/go-cty v1.16.2
2025-10-17T18:35:52.190+0530 [INFO] Go runtime version: go1.24.2
2025-10-17T18:35:52.190+0530 [INFO] CLI args: []string{"terraform", "import", "cloudstack_traffic_type.management", "d952bc43-214d-4df6-addb-b055d2a842b2"}
2025-10-17T18:35:52.190+0530 [DEBUG] Attempting to open CLI config file: /Users/kiranchavala/.terraformrc
2025-10-17T18:35:52.190+0530 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2025-10-17T18:35:52.190+0530 [DEBUG] checking for credentials in "/Users/kiranchavala/.terraform.d/plugins"
2025-10-17T18:35:52.190+0530 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2025-10-17T18:35:52.190+0530 [DEBUG] will search for provider plugins in /Users/kiranchavala/.terraform.d/plugins
2025-10-17T18:35:52.190+0530 [DEBUG] ignoring non-existing provider search directory /Users/kiranchavala/Library/Application Support/io.terraform/plugins
2025-10-17T18:35:52.190+0530 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2025-10-17T18:35:52.190+0530 [INFO] CLI command args: []string{"import", "cloudstack_traffic_type.management", "d952bc43-214d-4df6-addb-b055d2a842b2"}
2025-10-17T18:35:52.220+0530 [DEBUG] checking for provisioner in "."
2025-10-17T18:35:52.222+0530 [DEBUG] checking for provisioner in "/opt/homebrew/bin"
2025-10-17T18:35:52.222+0530 [DEBUG] checking for provisioner in "/Users/kiranchavala/.terraform.d/plugins"
2025-10-17T18:35:52.225+0530 [DEBUG] Building and walking import graph
2025-10-17T18:35:52.225+0530 [DEBUG] Not attaching any node states: overall state is nil
2025-10-17T18:35:52.225+0530 [DEBUG] No state, no orphan outputs
2025-10-17T18:35:52.225+0530 [DEBUG] ProviderTransformer: "cloudstack_traffic_type.management (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/cloudstack/cloudstack"]
2025-10-17T18:35:52.226+0530 [DEBUG] created provider logger: level=debug
2025-10-17T18:35:52.226+0530 [INFO] provider: configuring client automatic mTLS
2025-10-17T18:35:52.235+0530 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack args=[".terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack"]
2025-10-17T18:35:52.237+0530 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack pid=68333
2025-10-17T18:35:52.237+0530 [DEBUG] provider: waiting for RPC address: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack
2025-10-17T18:35:52.259+0530 [INFO] provider.terraform-provider-cloudstack: configuring server automatic mTLS: timestamp="2025-10-17T18:35:52.259+0530"
2025-10-17T18:35:52.269+0530 [DEBUG] provider.terraform-provider-cloudstack: plugin address: address=/var/folders/2f/6r19_y2s5p92vdzq4l29n0lr0000gn/T/plugin2420082724 network=unix timestamp="2025-10-17T18:35:52.268+0530"
2025-10-17T18:35:52.269+0530 [DEBUG] provider: using plugin: version=6
2025-10-17T18:35:52.285+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-17T18:35:52.286+0530 [INFO] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack id=68333
2025-10-17T18:35:52.286+0530 [DEBUG] provider: plugin exited
2025-10-17T18:35:52.286+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_api_url" references: []
2025-10-17T18:35:52.286+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_api_key" references: []
2025-10-17T18:35:52.286+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_secret_key" references: []
2025-10-17T18:35:52.286+0530 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/cloudstack/cloudstack\"]" references: [var.cloudstack_api_key var.cloudstack_api_url var.cloudstack_secret_key]
2025-10-17T18:35:52.286+0530 [DEBUG] ReferenceTransformer: "cloudstack_traffic_type.management (expand)" references: []
2025-10-17T18:35:52.286+0530 [DEBUG] Starting graph walk: walkImport
2025-10-17T18:35:52.287+0530 [DEBUG] created provider logger: level=debug
2025-10-17T18:35:52.287+0530 [INFO] provider: configuring client automatic mTLS
2025-10-17T18:35:52.290+0530 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack args=[".terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack"]
2025-10-17T18:35:52.292+0530 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack pid=68334
2025-10-17T18:35:52.292+0530 [DEBUG] provider: waiting for RPC address: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack
2025-10-17T18:35:52.304+0530 [INFO] provider.terraform-provider-cloudstack: configuring server automatic mTLS: timestamp="2025-10-17T18:35:52.304+0530"
2025-10-17T18:35:52.313+0530 [DEBUG] provider.terraform-provider-cloudstack: plugin address: address=/var/folders/2f/6r19_y2s5p92vdzq4l29n0lr0000gn/T/plugin856108897 network=unix timestamp="2025-10-17T18:35:52.313+0530"
2025-10-17T18:35:52.313+0530 [DEBUG] provider: using plugin: version=6
2025-10-17T18:35:52.325+0530 [DEBUG] ReferenceTransformer: "cloudstack_traffic_type.management (import id \"d952bc43-214d-4df6-addb-b055d2a842b2\")" references: []
cloudstack_traffic_type.management: Importing from ID "d952bc43-214d-4df6-addb-b055d2a842b2"...
cloudstack_traffic_type.management: Import prepared!
Prepared cloudstack_traffic_type for import
cloudstack_traffic_type.management: Refreshing state... [id=d952bc43-214d-4df6-addb-b055d2a842b2]
2025-10-17T18:35:54.917+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-17T18:35:54.918+0530 [INFO] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack id=68334
2025-10-17T18:35:54.918+0530 [DEBUG] provider: plugin exited
2025-10-17T18:35:54.918+0530 [INFO] Writing state output to:
Import successful!
terraform show
# cloudstack_traffic_type.management:
resource "cloudstack_traffic_type" "management" {
id = "d952bc43-214d-4df6-addb-b055d2a842b2"
kvm_network_label = "cloudbr0"
physical_network_id = "79213e81-1498-45f6-ae02-02524c3b9831"
traffic_type = "Management"
xen_network_label = "xenbr0"
}
That's because you loaded a management one. Load one that isn't management.
Thanks @ilsaloving-gander was able to reproduce the issue
@Pearl1594 can you take a look at this issue
Steps to reproduce the issue
- Have a cloudstack env with 2 different traffic types
(localcloud) 🐱 > list traffictypes physicalnetworkid=79213e81-1498-45f6-ae02-02524c3b9831
{
"count": 2,
"traffictype": [
{
"id": "d952bc43-214d-4df6-addb-b055d2a842b2",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "79213e81-1498-45f6-ae02-02524c3b9831",
"traffictype": "Management",
"vmwarenetworklabel": "vSwitch0,,vmwaresvs",
"xennetworklabel": "Network0"
},
{
"id": "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9",
"kvmnetworklabel": "cloudbr0",
"physicalnetworkid": "79213e81-1498-45f6-ae02-02524c3b9831",
"traffictype": "Storage",
"vmwarenetworklabel": "vSwitch0,,vmwaresvs",
"xennetworklabel": "Network0"
}
]
}
- Have a terraform config
resource "cloudstack_traffic_type" "management" {
physical_network_id = "79213e81-1498-45f6-ae02-02524c3b9831"
type = "Storage"
kvm_network_label = "cloudbr0"
xen_network_label = "xenbr0"
vmware_network_label = "VM Network"
}
- Apply terraform import
TF_LOG=DEBUG terraform import cloudstack_traffic_type.management "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9"
2025-10-17T21:39:52.251+0530 [INFO] Terraform version: 1.12.1
2025-10-17T21:39:52.251+0530 [DEBUG] using github.com/hashicorp/go-tfe v1.74.1
2025-10-17T21:39:52.251+0530 [DEBUG] using github.com/hashicorp/hcl/v2 v2.23.1-0.20250203194505-ba0759438da2
2025-10-17T21:39:52.251+0530 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2025-10-17T21:39:52.251+0530 [DEBUG] using github.com/zclconf/go-cty v1.16.2
2025-10-17T21:39:52.251+0530 [INFO] Go runtime version: go1.24.2
2025-10-17T21:39:52.251+0530 [INFO] CLI args: []string{"terraform", "import", "cloudstack_traffic_type.management", "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9"}
2025-10-17T21:39:52.251+0530 [DEBUG] Attempting to open CLI config file: /Users/kiranchavala/.terraformrc
2025-10-17T21:39:52.251+0530 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2025-10-17T21:39:52.252+0530 [DEBUG] checking for credentials in "/Users/kiranchavala/.terraform.d/plugins"
2025-10-17T21:39:52.252+0530 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2025-10-17T21:39:52.252+0530 [DEBUG] will search for provider plugins in /Users/kiranchavala/.terraform.d/plugins
2025-10-17T21:39:52.252+0530 [DEBUG] ignoring non-existing provider search directory /Users/kiranchavala/Library/Application Support/io.terraform/plugins
2025-10-17T21:39:52.252+0530 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2025-10-17T21:39:52.252+0530 [INFO] CLI command args: []string{"import", "cloudstack_traffic_type.management", "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9"}
2025-10-17T21:39:52.286+0530 [DEBUG] checking for provisioner in "."
2025-10-17T21:39:52.291+0530 [DEBUG] checking for provisioner in "/opt/homebrew/bin"
2025-10-17T21:39:52.291+0530 [DEBUG] checking for provisioner in "/Users/kiranchavala/.terraform.d/plugins"
2025-10-17T21:39:52.295+0530 [DEBUG] Building and walking import graph
2025-10-17T21:39:52.296+0530 [DEBUG] Not attaching any node states: overall state is nil
2025-10-17T21:39:52.296+0530 [DEBUG] No state, no orphan outputs
2025-10-17T21:39:52.296+0530 [DEBUG] ProviderTransformer: "cloudstack_traffic_type.management (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/cloudstack/cloudstack"]
2025-10-17T21:39:52.296+0530 [DEBUG] created provider logger: level=debug
2025-10-17T21:39:52.296+0530 [INFO] provider: configuring client automatic mTLS
2025-10-17T21:39:52.305+0530 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack args=[".terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack"]
2025-10-17T21:39:52.308+0530 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack pid=84818
2025-10-17T21:39:52.308+0530 [DEBUG] provider: waiting for RPC address: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack
2025-10-17T21:39:52.331+0530 [INFO] provider.terraform-provider-cloudstack: configuring server automatic mTLS: timestamp="2025-10-17T21:39:52.331+0530"
2025-10-17T21:39:52.341+0530 [DEBUG] provider.terraform-provider-cloudstack: plugin address: address=/var/folders/2f/6r19_y2s5p92vdzq4l29n0lr0000gn/T/plugin732356607 network=unix timestamp="2025-10-17T21:39:52.341+0530"
2025-10-17T21:39:52.341+0530 [DEBUG] provider: using plugin: version=6
2025-10-17T21:39:52.361+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-17T21:39:52.362+0530 [INFO] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack id=84818
2025-10-17T21:39:52.362+0530 [DEBUG] provider: plugin exited
2025-10-17T21:39:52.362+0530 [DEBUG] ReferenceTransformer: "cloudstack_traffic_type.management (expand)" references: []
2025-10-17T21:39:52.362+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_api_url" references: []
2025-10-17T21:39:52.362+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_api_key" references: []
2025-10-17T21:39:52.362+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_secret_key" references: []
2025-10-17T21:39:52.362+0530 [DEBUG] ReferenceTransformer: "provider[\"registry.terraform.io/cloudstack/cloudstack\"]" references: [var.cloudstack_api_key var.cloudstack_api_url var.cloudstack_secret_key]
2025-10-17T21:39:52.363+0530 [DEBUG] Starting graph walk: walkImport
2025-10-17T21:39:52.363+0530 [DEBUG] created provider logger: level=debug
2025-10-17T21:39:52.363+0530 [INFO] provider: configuring client automatic mTLS
2025-10-17T21:39:52.367+0530 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack args=[".terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack"]
2025-10-17T21:39:52.368+0530 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack pid=84819
2025-10-17T21:39:52.369+0530 [DEBUG] provider: waiting for RPC address: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack
2025-10-17T21:39:52.381+0530 [INFO] provider.terraform-provider-cloudstack: configuring server automatic mTLS: timestamp="2025-10-17T21:39:52.381+0530"
2025-10-17T21:39:52.390+0530 [DEBUG] provider.terraform-provider-cloudstack: plugin address: address=/var/folders/2f/6r19_y2s5p92vdzq4l29n0lr0000gn/T/plugin3545733515 network=unix timestamp="2025-10-17T21:39:52.390+0530"
2025-10-17T21:39:52.390+0530 [DEBUG] provider: using plugin: version=6
2025-10-17T21:39:52.401+0530 [DEBUG] ReferenceTransformer: "cloudstack_traffic_type.management (import id \"d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9\")" references: []
cloudstack_traffic_type.management: Importing from ID "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9"...
cloudstack_traffic_type.management: Import prepared!
Prepared cloudstack_traffic_type for import
cloudstack_traffic_type.management: Refreshing state... [id=d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9]
2025-10-17T21:39:53.122+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-10-17T21:39:53.125+0530 [INFO] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/cloudstack/cloudstack/0.6.0-rc3/darwin_arm64/terraform-provider-cloudstack id=84819
2025-10-17T21:39:53.125+0530 [DEBUG] provider: plugin exited
2025-10-17T21:39:53.125+0530 [INFO] Writing state output to:
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
- The traffic type still shows as Mangement
terraform show
# cloudstack_traffic_type.management:
resource "cloudstack_traffic_type" "management" {
id = "d2d1c8f7-ae4f-45f4-9b29-e3f45ed8d0d9"
kvm_network_label = "cloudbr0"
physical_network_id = "79213e81-1498-45f6-ae02-02524c3b9831"
traffic_type = "Management"
xen_network_label = "xenbr0"
}
There are a number of issues making importing this resource inoperable. See https://github.com/apache/cloudstack/issues/7837.
Additionally, it looks like the resource is comparing the name to traffictype.
// Set the type attribute - use the original value from the API call
// If the Name field is empty, use a default value based on the traffic type ID
if tt.Name != "" {
d.Set("traffic_type", tt.Name)
} else {
// Use a default value based on common traffic types
// This is a fallback and might not be accurate
d.Set("traffic_type", "Management")
}
Traffic type isn't set in the API spec. Oddly, as noted in this thread, it is returned in the response.
- https://pkg.go.dev/github.com/apache/cloudstack-go/[email protected]/cloudstack#TrafficType
- https://cloudstack.apache.org/api/apidocs-4.19/apis/listTrafficTypes.html
type TrafficType struct {
Canenableindividualservice [bool](https://pkg.go.dev/builtin#bool) `json:"canenableindividualservice"`
Destinationphysicalnetworkid [string](https://pkg.go.dev/builtin#string) `json:"destinationphysicalnetworkid"`
Id [string](https://pkg.go.dev/builtin#string) `json:"id"`
JobID [string](https://pkg.go.dev/builtin#string) `json:"jobid"`
Jobstatus [int](https://pkg.go.dev/builtin#int) `json:"jobstatus"`
Name [string](https://pkg.go.dev/builtin#string) `json:"name"`
Physicalnetworkid [string](https://pkg.go.dev/builtin#string) `json:"physicalnetworkid"`
Servicelist [][string](https://pkg.go.dev/builtin#string) `json:"servicelist"`
State [string](https://pkg.go.dev/builtin#string) `json:"state"`
}
Exactly. It could be fixed, by changing the json name to traffictype maybe, but that entirely depends on what the underlying library sends you. If it sends you incorrect data, then there's not a lot to be done.
Unfortunately this makes the plugin useless for managing cloudstack infrastructure. :(
Will address this - but this may not go into the 0.6.0 release of the provider as this requires a change upstream.
What do you need me to do? The output from the PR looks good, I guess?
@ilsaloving-gander i have tested pr and its working fine
Moving it next milestone release of terraform 0.7 as it needs a newer cloudstack release and cloudstack-go release for it to work.