cli: manual AWS terraform state transitions

This commit is designed to be reverted in the future (AB#3248).
Terraform does not implement moved blocks with dynamic targets: https://github.com/hashicorp/terraform/issues/31335 so we have to migrate the terraform state ourselves.
This commit is contained in:
Malte Poll 2023-06-27 13:12:50 +02:00 committed by Malte Poll
parent 22ebdace43
commit 3edc1c3ebb
9 changed files with 183 additions and 6 deletions

View file

@ -94,9 +94,11 @@ type Upgrader struct {
helmClient helmInterface
imageFetcher imageFetcher
outWriter io.Writer
tfUpgrader *upgrade.TerraformUpgrader
log debugLog
upgradeID string
// TODO(AB#3248): Remove this tfClient after we can assume that all existing clusters have been migrated.
tfClient *terraform.Client
tfUpgrader *upgrade.TerraformUpgrader
log debugLog
upgradeID string
}
// NewUpgrader returns a new Upgrader.
@ -144,6 +146,7 @@ func NewUpgrader(ctx context.Context, outWriter io.Writer, log debugLog, upgrade
if err != nil {
return nil, fmt.Errorf("setting up terraform client: %w", err)
}
u.tfClient = tfClient
tfUpgrader, err := upgrade.NewTerraformUpgrader(tfClient, outWriter)
if err != nil {
@ -154,6 +157,12 @@ func NewUpgrader(ctx context.Context, outWriter io.Writer, log debugLog, upgrade
return u, nil
}
// AddManualStateMigration adds a manual state migration to the Terraform client.
// TODO(AB#3248): Remove this method after we can assume that all existing clusters have been migrated.
func (u *Upgrader) AddManualStateMigration(migration terraform.StateMigration) {
u.tfClient.WithManualStateMigration(migration)
}
// CheckTerraformMigrations checks whether Terraform migrations are possible in the current workspace.
// If the files that will be written during the upgrade already exist, it returns an error.
func (u *Upgrader) CheckTerraformMigrations(fileHandler file.Handler) error {