-
Notifications
You must be signed in to change notification settings - Fork 961
Expand file tree
/
Copy pathmigrate_github_actions_secret.go
More file actions
36 lines (28 loc) · 1.03 KB
/
migrate_github_actions_secret.go
File metadata and controls
36 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package github
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func resourceGithubActionsSecretMigrateState(v int, is *terraform.InstanceState, meta any) (*terraform.InstanceState, error) {
switch v {
case 0:
log.Printf("[INFO] Found GitHub Actions Secret State v0; migrating to v1")
return migrateGithubActionsSecretStateV0toV1(is)
default:
return is, fmt.Errorf("unexpected schema version: %d", v)
}
}
func migrateGithubActionsSecretStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
if is.Empty() {
log.Printf("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}
log.Printf("[DEBUG] GitHub Actions Secret Attributes before migration: %#v", is.Attributes)
// Add the destroy_on_drift field with default value true if it doesn't exist
if _, ok := is.Attributes["destroy_on_drift"]; !ok {
is.Attributes["destroy_on_drift"] = "true"
}
log.Printf("[DEBUG] GitHub Actions Secret Attributes after State Migration: %#v", is.Attributes)
return is, nil
}