apache / apache/cloudstack-terraform-provider

Add import support to cloudstack_domain (requires implementing the currently no-op Read)

Offen
#304 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
improvement
Vorherrschende Sprache
Go
Sterne
53
Forks
67
Ø Merge
3 T. 14 Std.
Gemergte PRs (30 T.)
15

Beschreibung

### Summary

`cloudstack_domain` (cloudstack/resource_cloudstack_domain.go) currently declares no
`Importer`, so pre-existing domains cannot be brought under Terraform management. Since the
domain tree is typically created long before Terraform adoption, import support is essential
for brownfield adoption and for codifying an existing CloudStack environment.

### Current state

Two things block import today:

1. The resource schema declares no `schema.ResourceImporter`.
2. `resourceCloudStackDomainRead` is a stub that makes no API call:

func resourceCloudStackDomainRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

Adding an importer alone would therefore import an empty state - a working `Read` is a
prerequisite. (The stub also means the resource never detects drift or out-of-band deletion
for domains it created, so implementing `Read` fixes refresh behavior as a side benefit.)

### Proposed change

1. Implement `resourceCloudStackDomainRead`:
- call `listDomains` with `id=d.Id()` (and `listall=true`),
- on `count: 0`, call `d.SetId("")` so Terraform drops the missing resource,
- populate the schema attributes from the response (`name`, `network_domain`,
`parent_domain_id` from `parentdomainid`, `domain_id`).
2. Add the importer, following the same pattern used by the other SDK-based resources in this
provider:

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

The import id would be the domain UUID, consistent with the other resources.

Note that `listDomains` is an admin-scoped command, but that matches the resource itself -
only admins can create domains, so any credentials able to manage `cloudstack_domain` can
also read it.

### Environment

- Provider version: latest
- CloudStack version: latest

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne in cloudstack/resource_cloudstack_domain.go mit resourceCloudStackDomainRead und dem Ressourcenschema und vergleiche anschließend das von anderen SDK-basierten Ressourcen verwendete Importer-Muster. Verfolge listDomains mit einer ID und führe die relevanten Provider-Tests aus; fertig ist es, wenn importierte Domains die aufgeführten Attribute befüllen und nicht vorhandene Domains aus dem State entfernt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
go, terraform
Bereich
cloud, infrastructure
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
74/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.