Skip to content

Commit

Permalink
Add state upgraders to support revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Udit committed Nov 1, 2020
1 parent 5308f7e commit bd1e62e
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions github/migrate_github_branch_protection.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package github

import "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func resourceGithubBranchProtectionV0() *schema.Resource {
return &schema.Resource{
Expand Down Expand Up @@ -33,8 +37,39 @@ func resourceGithubBranchProtectionUpgradeV0(rawState map[string]interface{}, me
}

rawState["id"] = protectionRuleID
rawState[REPOSITORY_ID] = repoID
rawState[PROTECTION_PATTERN] = branch
rawState["repository_id"] = repoID
rawState["pattern"] = branch

return rawState, nil
}

func resourceGithubBranchProtectionV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"repository_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"pattern": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}

func resourceGithubBranchProtectionUpgradeV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {

repoName, err := getRepositoryName(rawState["repository_id"].(string), meta)
if err != nil {
return nil, err
}

rawState["repository"] = repoName
rawState["branch"] = rawState["pattern"]
rawState["id"] = fmt.Sprintf("%s:%s", rawState["repository"], rawState["branch"])

return rawState, nil
}

0 comments on commit bd1e62e

Please sign in to comment.