-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathmigrate_github_repository.go
More file actions
40 lines (31 loc) · 993 Bytes
/
migrate_github_repository.go
File metadata and controls
40 lines (31 loc) · 993 Bytes
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
37
38
39
40
package github
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func resourceGithubRepositoryMigrateState(v int, is *terraform.InstanceState, meta any) (*terraform.InstanceState, error) {
switch v {
case 0:
log.Printf("[INFO] Found GitHub Repository State v0; migrating to v1")
return migrateGithubRepositoryStateV0toV1(is)
default:
return is, fmt.Errorf("unexpected schema version: %d", v)
}
}
func migrateGithubRepositoryStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
if is.Empty() {
log.Printf("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}
log.Printf("[DEBUG] GitHub Repository Attributes before migration: %#v", is.Attributes)
prefix := "branches."
for k := range is.Attributes {
if strings.HasPrefix(k, prefix) {
delete(is.Attributes, k)
}
}
log.Printf("[DEBUG] GitHub Repository Attributes after State Migration: %#v", is.Attributes)
return is, nil
}