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

Simplify Service import logic, and allow selecting a version while importing #448

Merged
merged 2 commits into from
Jul 23, 2021
Merged

Simplify Service import logic, and allow selecting a version while importing #448

merged 2 commits into from
Jul 23, 2021

Conversation

bengesoff
Copy link
Contributor

Previously the Service resource import would do a full state refresh twice: once in the resourceImport function, and again when Terraform calls resourceRead again afterwards. This PR simplifies this, to only optionally set the cloned_version in the resourceImport function, and delegate the rest of the state refresh to the resourceRead called by Terraform automatically.

If no version is specified for the import, then the Read function will detect cloned_version is 0, and select either the active version or latest version. This logic hasn't changed, but the isImport flag argument is no longer needed.

In simplifying the import logic, it seemed like a good opportunity to add a new feature: allowing @ and a version number to be appended to the ID whilst importing, to enable the user to choose a version. This is optional, and the previous method of only specifying the ID without the version is still supported.

Previously the service resource importer was doing a full state refresh.
This was redundant because the Read function gets called right after the Import one, so the state was being refreshed twice.
It also introduced extra logic in the Read function to determine whether it was being called via the Import function or not, to enable the version selection logic to be tweaked.

This commit changes the behaviour so that the Import function only has one responsibility; to set cloned_version.
The rest of the state read is then fully delegated to the Read function, which needs no extra logic to determine the version, as it should already be set.

The Import function has been given some extra logic, to optionally parse a version number from the provided ID, by using an '@' symbol after the ID.
If it isn't specified, i.e. only the ID is used, then the Read function will default to the active version, or the latest version if that is not set either.
@bengesoff bengesoff marked this pull request as ready for review July 23, 2021 09:22
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

LGTM. Just one unrelated question @bengesoff

@Integralist Integralist added the enhancement New feature or request label Jul 23, 2021
@Integralist Integralist merged commit 5586ff2 into fastly:main Jul 23, 2021
@bengesoff bengesoff deleted the simplify-service-importer branch July 23, 2021 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants