Skip to content

Add terraform import support for several cloudstack resources#305

Draft
Pearl1594 wants to merge 3 commits into
mainfrom
add-import-support
Draft

Add terraform import support for several cloudstack resources#305
Pearl1594 wants to merge 3 commits into
mainfrom
add-import-support

Conversation

@Pearl1594

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 22, 2026 20:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds Terraform import support across a set of CloudStack provider resources by wiring in Importer blocks (including project-aware passthrough where needed), introducing a few custom import state resolvers (e.g., for resources that Read-by-name or that need to materialize nested rule sets), and documenting the expected import IDs. It also adds/extends acceptance tests to validate import behavior for several of the updated resources.

Changes:

  • Added Importer support to multiple resources, using either passthrough import or custom import-state functions where an ID-to-name (or ID-to-ruleset) translation is required.
  • Implemented custom import logic for port-forwarding rules and for offerings that are read back by name (service/network offerings).
  • Added import documentation sections and import acceptance tests for several resources.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
website/docs/r/vpn_connection.html.markdown Documents cloudstack_vpn_connection import usage.
website/docs/r/static_nat.html.markdown Documents cloudstack_static_nat import usage, including project-prefixed IDs.
website/docs/r/port_forward.html.markdown Documents cloudstack_port_forward import behavior and managed-rule import semantics.
website/docs/r/loadbalancer_rule.html.markdown Documents cloudstack_loadbalancer_rule import usage and write-only field caveat.
website/docs/r/ipaddress.html.markdown Documents cloudstack_ipaddress import usage, including project-prefixed IDs.
website/docs/r/counter.html.markdown Documents cloudstack_counter import usage.
website/docs/r/condition.html.markdown Documents cloudstack_condition import usage.
website/docs/r/autoscale_vm_profile.html.markdown Documents cloudstack_autoscale_vm_profile import usage.
website/docs/r/autoscale_policy.html.markdown Documents cloudstack_autoscale_policy import usage.
cloudstack/resource_cloudstack_vpn_connection.go Adds passthrough importer for VPN connections.
cloudstack/resource_cloudstack_vpn_connection_test.go Adds acceptance import test for VPN connections.
cloudstack/resource_cloudstack_static_nat.go Enables project-aware passthrough import for static NAT.
cloudstack/resource_cloudstack_static_nat_test.go Adds acceptance import test for static NAT.
cloudstack/resource_cloudstack_service_offering.go Adds importer that resolves offering name from ID before refresh.
cloudstack/resource_cloudstack_service_offering_test.go Adds acceptance import test for service offerings.
cloudstack/resource_cloudstack_port_forward.go Adds custom importer that imports all port forwarding rules for an IP into the forward set and forces managed=true.
cloudstack/resource_cloudstack_port_forward_test.go Adds acceptance import test for port forwards (ignoring managed).
cloudstack/resource_cloudstack_network_offering.go Adds importer that resolves network offering name from ID before refresh.
cloudstack/resource_cloudstack_loadbalancer_rule.go Enables project-aware passthrough import for load balancer rules.
cloudstack/resource_cloudstack_loadbalancer_rule_test.go Adds acceptance import test for load balancer rules (ignoring certificate_id).
cloudstack/resource_cloudstack_ipaddress.go Enables project-aware passthrough import for IP addresses.
cloudstack/resource_cloudstack_ipaddress_test.go Adds acceptance import test for IP addresses.
cloudstack/resource_cloudstack_host.go Adds passthrough importer for hosts.
cloudstack/resource_cloudstack_host_test.go Adds acceptance import test for hosts with appropriate ignore list for write-only/provider-local fields.
cloudstack/resource_cloudstack_counter.go Adds passthrough importer for counters.
cloudstack/resource_cloudstack_condition.go Adds passthrough importer for conditions.
cloudstack/resource_cloudstack_autoscale_vm_profile.go Adds passthrough importer for autoscale VM profiles.
cloudstack/resource_cloudstack_autoscale_vm_profile_test.go Adds import acceptance test but currently skips it unconditionally.
cloudstack/resource_cloudstack_autoscale_vm_group.go Adds passthrough importer for autoscale VM groups.
cloudstack/resource_cloudstack_autoscale_policy.go Adds passthrough importer for autoscale policies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread website/docs/r/vpn_connection.html.markdown
Comment thread website/docs/r/counter.html.markdown
Comment thread website/docs/r/condition.html.markdown
Comment thread website/docs/r/autoscale_vm_profile.html.markdown
Comment thread website/docs/r/autoscale_policy.html.markdown
Comment on lines +88 to +90
func TestAccCloudStackAutoscaleVMProfile_import(t *testing.T) {
t.Skip("Skipping due to bug in cloudstack-go library")

Copilot AI review requested due to automatic review settings July 24, 2026 02:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

cloudstack/resource_cloudstack_autoscale_vm_profile_test.go:90

  • This acceptance test is unconditionally skipped, so the new import support for cloudstack_autoscale_vm_profile isn’t exercised in CI and regressions won’t be caught. If there’s an upstream cloudstack-go issue, consider making the skip conditional (only for affected CloudStack/cloudstack-go versions) and/or referencing a tracking issue so it’s clear when it can be re-enabled.
func TestAccCloudStackAutoscaleVMProfile_import(t *testing.T) {
	t.Skip("Skipping due to bug in cloudstack-go library")

website/docs/r/vpn_connection.html.markdown:46

  • The example import ID isn’t a valid UUID (the first group has 7 hex characters). Using an invalid-looking ID makes the copy/paste example confusing; use an 8-4-4-4-12 UUID format in the example.
VPN Connections can be imported using the `id`, e.g.

```shell
$ terraform import cloudstack_vpn_connection.default 6eb22f91-7454-4107-89f4-36afcdf33021
**website/docs/r/counter.html.markdown:51**
* The example import ID isn’t a valid UUID (the first group has 7 hex characters). Using an invalid-looking ID makes the copy/paste example confusing; use an 8-4-4-4-12 UUID format in the example.

Counters can be imported using the id, e.g.

$ terraform import cloudstack_counter.default 6eb22f91-7454-4107-89f4-36afcdf33021
</details>

Comment on lines +239 to +247
// Try to split the ID to extract the optional project name.
s := strings.SplitN(d.Id(), "/", 2)
if len(s) == 2 {
d.Set("project", s[0])
}

ipAddressID := s[len(s)-1]
d.SetId(ipAddressID)

Copilot AI review requested due to automatic review settings July 24, 2026 02:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

cloudstack/resource_cloudstack_autoscale_vm_profile_test.go:90

  • The newly added import acceptance test is unconditionally skipped, so the PR adds import functionality without any automated validation. Either make the skip conditional (e.g., only for specific CloudStack versions) or link to the upstream cloudstack-go issue and track removing the skip so import stays covered.
func TestAccCloudStackAutoscaleVMProfile_import(t *testing.T) {
	t.Skip("Skipping due to bug in cloudstack-go library")

Comment on lines +89 to +91
*NOTE: All existing port forwarding rules for the IP address are imported into
a single `forward` set, and `managed` is set to `true` so unrelated rules
created outside of this resource aren't dropped on the next apply.*
Comment on lines +313 to +316
d.Set("forward", forwards)
d.Set("managed", true)

return []*schema.ResourceData{d}, nil
Comment on lines +74 to +76
// The importer sets managed=true so unrelated forwards on the same IP
// aren't silently dropped; the applied config leaves it at its default.
ImportStateVerifyIgnore: []string{"managed"},
Comment on lines +37 to +39
Importer: &schema.ResourceImporter{
State: resourceCloudStackServiceOfferingImport,
},
Comment on lines +36 to +38
Importer: &schema.ResourceImporter{
State: resourceCloudStackNetworkOfferingImport,
},
Comment on lines +40 to +42
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Comment on lines +78 to +84
## Import

Autoscale VM profiles can be imported using the `id`, e.g.

```shell
$ terraform import cloudstack_autoscale_vm_profile.default 6eb22f91-7454-4107-89f4-36afcdf33021
```
Copilot AI review requested due to automatic review settings July 24, 2026 14:38
@Pearl1594
Pearl1594 force-pushed the add-import-support branch from 663fbb5 to 57ef4b1 Compare July 24, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (6)

cloudstack/resource_cloudstack_autoscale_vm_profile_test.go:89

  • This import acceptance test is currently always skipped, which means the new import functionality won’t be exercised in CI. Please include a specific upstream issue/PR reference in the skip message so it’s easy to track when it can be re-enabled.
	t.Skip("Skipping due to bug in cloudstack-go library")

website/docs/r/vpn_connection.html.markdown:46

  • The example import ID is not a valid UUID (it’s missing a leading hex digit). This can break copy/paste usage; use a properly formatted UUID in the example.
VPN Connections can be imported using the `id`, e.g.

```shell
$ terraform import cloudstack_vpn_connection.default eb22f91-7454-4107-89f4-36afcdf33021
**website/docs/r/counter.html.markdown:51**
* The example import ID is not a valid UUID (it’s missing a leading hex digit). This can break copy/paste usage; use a properly formatted UUID in the example.

Counters can be imported using the id, e.g.

$ terraform import cloudstack_counter.default eb22f91-7454-4107-89f4-36afcdf33021
**website/docs/r/condition.html.markdown:69**
* The example import ID is not a valid UUID (it’s missing a leading hex digit). This can break copy/paste usage; use a properly formatted UUID in the example.

Conditions can be imported using the id, e.g.

$ terraform import cloudstack_condition.default eb22f91-7454-4107-89f4-36afcdf33021
**website/docs/r/autoscale_vm_profile.html.markdown:84**
* The example import ID is not a valid UUID (it’s missing a leading hex digit). This can break copy/paste usage; use a properly formatted UUID in the example.

Autoscale VM profiles can be imported using the id, e.g.

$ terraform import cloudstack_autoscale_vm_profile.default eb22f91-7454-4107-89f4-36afcdf33021
**website/docs/r/autoscale_policy.html.markdown:71**
* The example import ID is not a valid UUID (it’s missing a leading hex digit). This can break copy/paste usage; use a properly formatted UUID in the example.

Autoscale policies can be imported using the id, e.g.

$ terraform import cloudstack_autoscale_policy.default eb22f91-7454-4107-89f4-36afcdf33021
</details>

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

Successfully merging this pull request may close these issues.

2 participants