equinix / terraform-provider-equinix

Terraform Equinix provider
https://deploy.equinix.com/labs/terraform-provider-equinix/
MIT License
47 stars 45 forks source link

[Feature]: Migrate resources to terraform plugin framework #612

Open ocobles opened 7 months ago

ocobles commented 7 months ago

We are in the process of migrating all Terraform resources previously defined using the SDKv2 to the Terraform Framework. The utilization of the terraform-plugin-mux Go module has been successfully implemented to facilitate the gradual migration of resources. We have also adopted internal/ layout structure so the resources that are migrated to the framework must now be in their own compartment within internal/{services}/{resource}

Migrate to terraform plugin framework adopt internal/ layout structure #106

Checklist for Unmigrated Resources

Fabric Resources

Metal Resources

Network Edge Resources

Checklist for Unmigrated Datasources

Fabric Datasources

Metal Datasources

Network Edge Datasources

Migration Guide

Code in https://github.com/equinix/terraform-provider-equinix/blob/framework_migr_resources/internal/metal_organization/resource.go should be used as a base to migrate this resource.

Checkout the sdkv2 version https://github.com/equinix/terraform-provider-equinix/blob/main/equinix/resource_metal_organization.go

Checkout official documentation https://developer.hashicorp.com/terraform/plugin/framework/migrating/attributes-blocks/blocks for mapping between SDK Schema Fields and the Framewor. Here's also the link to recommended steps https://developer.hashicorp.com/terraform/plugin/framework/migrating#migration-steps

  1. Code structure:

    • Separate the code into the following files:
      • models.go
      • resource.go
      • resource_schema.go
      • resource_test.go
  2. Schema Review:

    • Review the resource schema and compare it with the SDKv2 code to ensure no validation or planmodifier has been forgotten.
  3. Update Imports:

    • Review and update imports as necessary. Some imports might have been renamed or moved.
  4. Rename Functions and Variables:

    • Rename functions and variables to follow the same standards as in the already migrated resources (e.g., OrganizationResourceModel to ResourceModel or organizationResourceSchema to resourceSchema).
  5. Migrate End-to-End Tests (e2e):

    • Update end-to-end tests (e2e) to use ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories instead of Providers: testAccProviders.
    • Add an additional test to verify the migration is correct. You can use the test added in ssh_key as a reference, TestAccMetalSSHKey_upgradeFromVersion.
  6. Verification and Testing:

    • Verify that the new code functions as expected and that all tests pass.
  7. Migrate Equivalent Data Source (if applicable):

    • If there exists an equivalent data source for the resource being migrated, it should also be migrated in the same Pull Request (PR).
    • Follow the same steps as above for migrating the data source, using the following files:
      • datasource.go
      • datasource_test.go
      • datasource_schema.go
    • Ensure that the data source is updated to match the changes made in the resource migration.
ctreatma commented 7 months ago

~Noting here that ECX resources are probably not worth migrating, since the ECX API will be shut down this year, after which time the resources can be deleted entirely.~. ECX support was removed in v2.0.0 and I have removed those resources & data sources from the issue description.