-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #801 from hashicorp/mwudka/TF-8621-add-data-retent…
…ion-policy-support Allow managing StateVersion and ConfigurationVersion backing data
- Loading branch information
Showing
8 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
tfe "github.com/hashicorp/go-tfe" | ||
"log" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
action := flag.String("action", "", "Action (soft-delete|restore|permanently-delete") | ||
externalId := flag.String("external-id", "", "External ID of StateVersion or ConfigurationVersion") | ||
|
||
flag.Parse() | ||
|
||
if action == nil || *action == "" { | ||
log.Fatal("No Action provided") | ||
} | ||
|
||
if externalId == nil || *externalId == "" { | ||
log.Fatal("No external ID provided") | ||
} | ||
|
||
ctx := context.Background() | ||
client, err := tfe.NewClient(&tfe.Config{ | ||
RetryServerErrors: true, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = performAction(ctx, client, *action, *externalId) | ||
if err != nil { | ||
log.Fatalf("Error performing action: %v", err) | ||
} | ||
} | ||
|
||
func performAction(ctx context.Context, client *tfe.Client, action string, id string) error { | ||
externalIdParts := strings.Split(id, "-") | ||
switch externalIdParts[0] { | ||
case "cv": | ||
switch action { | ||
case "soft-delete": | ||
return client.ConfigurationVersions.SoftDeleteBackingData(ctx, id) | ||
case "restore": | ||
return client.ConfigurationVersions.RestoreBackingData(ctx, id) | ||
case "permanently-delete": | ||
return client.ConfigurationVersions.PermanentlyDeleteBackingData(ctx, id) | ||
default: | ||
return fmt.Errorf("unsupported action: %s", action) | ||
} | ||
case "sv": | ||
switch action { | ||
case "soft-delete": | ||
return client.StateVersions.SoftDeleteBackingData(ctx, id) | ||
case "restore": | ||
return client.StateVersions.RestoreBackingData(ctx, id) | ||
case "permanently-delete": | ||
return client.StateVersions.PermanentlyDeleteBackingData(ctx, id) | ||
default: | ||
return fmt.Errorf("unsupported action: %s", action) | ||
} | ||
default: | ||
return fmt.Errorf("unsupported external ID: %s", id) | ||
} | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters