Skip to content
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

Import compound resources (experimental) #1104

Merged
merged 38 commits into from
Aug 28, 2023

Conversation

dataclouder
Copy link
Collaborator

@dataclouder dataclouder commented Aug 6, 2023

This PR explores the experimental Terraform import capabilities to use with some resources that have components not handled by Terraform.

Specifically, we try to facilitate the usage of

  • shared catalogs (the vApp templates and media items are available to the receiving user, but they are not in Terraform state)
  • cloned vApps, created by either a vApp template or another vApp, where the VMs are created without Terraform intervention.

In practical terms, this PR does the following:

  • Adds the ability of creating a file containing import blocks using vcd_resource_list (property import_file_name);
  • Changes the internals of vcd_resource_list to use genericResourceList for all resources. Therefore, we can create files with import blocks for all resources;
  • Adds several resources to the list supported by vcd_resource_list
    • vcd_provider_vdc
    • vcd_org_ldap
    • vcd_org_saml
    • vcd_vdc_group
    • vcd_catalog_access_control
    • vcd_vapp_access_control
    • vcd_org_vdc_access_control
    • vcd_subscribed_catalog
    • vcd_cloned_vapp
    • vcd_edgegateway_settings
  • Adds a guide on how to import resources using this experimental feature.
  • Adds examples code for vApp/VMs import
  • Adds examples code for catalog and contents import

Example:

Using this setup:

data "vcd_resource_list" "vms_from_vapp" {
  resource_type    = "vcd_vapp_vm"
  name             = "vms_from_vapp"
  parent           = vcd_cloned_vapp.vapp_from_vapp.name
  list_mode        = "import"
  import_file_name = "vms_from_vapp.tf"
}

data "vcd_resource_list" "vms_from_template" {
  resource_type    = "vcd_vapp_vm"
  name             = "vms_from_template"
  parent           = vcd_cloned_vapp.vapp_from_template.name
  list_mode        = "import"
  import_file_name = "vms_from_template.tf"
}

We obtain these files:

$ cat vms_from_template.tf vms_from_vapp.tf
# Generated by vcd_resource_list - 2023-08-06T16:30:10+02:00
# import data for vcd_vapp_vm datacloud.nsxt-vdc-datacloud.ClonedVAppFromTemplate.thirdVM
import {
  to = vcd_vapp_vm.thirdVM-a2aed82f4120
  id = "datacloud.nsxt-vdc-datacloud.ClonedVAppFromTemplate.thirdVM"
}

# import data for vcd_vapp_vm datacloud.nsxt-vdc-datacloud.ClonedVAppFromTemplate.firstVM
import {
  to = vcd_vapp_vm.firstVM-05781b374e0f
  id = "datacloud.nsxt-vdc-datacloud.ClonedVAppFromTemplate.firstVM"
}

# import data for vcd_vapp_vm datacloud.nsxt-vdc-datacloud.ClonedVAppFromTemplate.secondVM
import {
  to = vcd_vapp_vm.secondVM-297d88653cb3
  id = "datacloud.nsxt-vdc-datacloud.ClonedVAppFromTemplate.secondVM"
}

# Generated by vcd_resource_list - 2023-08-06T16:30:16+02:00
# import data for vcd_vapp_vm datacloud.nsxt-vdc-datacloud.AccClonedVAppFromVapp.thirdVM
import {
  to = vcd_vapp_vm.thirdVM-83f3fa702d07
  id = "datacloud.nsxt-vdc-datacloud.AccClonedVAppFromVapp.thirdVM"
}

# import data for vcd_vapp_vm datacloud.nsxt-vdc-datacloud.AccClonedVAppFromVapp.secondVM
import {
  to = vcd_vapp_vm.secondVM-038396a0070c
  id = "datacloud.nsxt-vdc-datacloud.AccClonedVAppFromVapp.secondVM"
}

# import data for vcd_vapp_vm datacloud.nsxt-vdc-datacloud.AccClonedVAppFromVapp.firstVM
import {
  to = vcd_vapp_vm.firstVM-0662aa45c523
  id = "datacloud.nsxt-vdc-datacloud.AccClonedVAppFromVapp.firstVM"
}

With this setup, we can run the command

terraform plan -generate-config-out=generated_vms.tf

and the next terraform apply will import the new resources in state.

Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Makes all lists consistent, thus able to generate import files

Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
@dataclouder dataclouder self-assigned this Aug 6, 2023
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
@dataclouder dataclouder marked this pull request as ready for review August 10, 2023 10:24
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
* vcd_org_ldap
* vcd_org_saml
* vcd_vdc_group
* vcd_catalog_access_control
* vcd_vapp_access_control
* vcd_org_vdc_access_control
* vcd_subscribed_catalog
* vcd_cloned_vapp
* vcd_edgegateway_settings

Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
@adezxc
Copy link
Contributor

adezxc commented Aug 22, 2023

Closes #1012

Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Copy link
Contributor

@adezxc adezxc left a comment

Choose a reason for hiding this comment

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

Looks good to me, again, very awesome implementation!

vcd/resource_vcd_catalog_media.go Show resolved Hide resolved
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

Very powerful addition. Great to see that we don't need much changes in code to support the new experimental import from Terraform.

I'm adding some in-line comments. Main ask is to add more references in code and docs for the "new experimental Terraform import", because when you're reading without context it's easy to miss that point.

Thanks!

.changes/v3.11.0/1104-experimental-features.md Outdated Show resolved Hide resolved
.changes/v3.11.0/1104-improvements.md Show resolved Hide resolved
.changes/sections Show resolved Hide resolved
website/docs/guides/importing_resources.html.markdown Outdated Show resolved Hide resolved
website/docs/guides/importing_resources.html.markdown Outdated Show resolved Hide resolved
website/docs/guides/importing_resources.html.markdown Outdated Show resolved Hide resolved
@dataclouder dataclouder changed the title Import compound resources Import compound resources (experimental) Aug 25, 2023
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

Thanks for all the additions!

Copy link
Collaborator

@adambarreiro adambarreiro left a comment

Choose a reason for hiding this comment

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

Very nice feature, the examples worked like a charm and it's a super-powerful tool.

website/docs/guides/importing_resources.html.markdown Outdated Show resolved Hide resolved
website/docs/r/catalog.html.markdown Outdated Show resolved Hide resolved
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
@dataclouder dataclouder merged commit b310b9e into vmware:main Aug 28, 2023
3 checks passed
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.

None yet

5 participants