Skip to content

Conversation

@graphaelli
Copy link
Member

Description

enable serverless project import with terraform import

Related Issues

closes #918

Motivation and Context

Allows management of existing projects.

How Has This Been Tested?

  • updated unit and acceptance tests
  • used with dev_overrides to import observability and elasticsearch projects manually

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improves code quality but has no user-facing effect)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation

Readiness Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Assisted by Cursor AI.

@graphaelli graphaelli requested a review from a team as a code owner January 5, 2026 20:15
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
// TODO(gr): reenable after checking the order of product_types is not important
Copy link
Member Author

Choose a reason for hiding this comment

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

This fails with product types because they are not in a stable order. There is already handling for order insensitive equality in

func (v ProductTypesListValue) ListSemanticEquals(ctx context.Context, otherV basetypes.ListValuable) (bool, diag.Diagnostics) {
but that's not called during import state verification.

@norrietaylor since you implemented this originally, thoughts on how to resolve this? Why is ListSemanticEquals separate from Equal? Can we sort the product lines as returned from the api or is the order significant elsewhere?

Copy link
Member

Choose a reason for hiding this comment

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

Does using their plancheck interface take semantic equality into account (IIUC it should since it's just asserting there's an empty plan)

				ImportPlanChecks: resource.ImportPlanChecks{
					PreApply: []plancheck.PlanCheck{
						plancheck.ExpectEmptyPlan(),
					},
				},

Why is ListSemanticEquals separate from Equal?

That's what the Terraform framework wants. Semantically equal values will be substituted by the prior value during plan/apply and so won't trigger errors due to inconsistent state.

Can we sort the product lines as returned from the api or is the order significant elsewhere?

We can, but we're then adding a bunch of code to workaround a test framework limitation which isn't ideal. I'd be surprised if we can't implement adequate validation via ImportPlanChecks

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @tobio. Do I understand correctly that just checking that there is an empty plan is the sufficient check? I've pushed a214fe4 with that change

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the late reply, yep an empty plan should be the equivalent of what ImportStateVerify accomplishes.

@dimuon dimuon merged commit cfe45fb into elastic:master Jan 8, 2026
4 checks passed
@graphaelli graphaelli deleted the import-serverless branch January 9, 2026 14:04
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.

Terraform import ec_elasticsearch_project doesn't work

3 participants