From bd1e62e60173513b6c3647424d77b25691df0c71 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Sun, 1 Nov 2020 15:33:00 -0500 Subject: [PATCH] Add state upgraders to support revert --- github/migrate_github_branch_protection.go | 41 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/github/migrate_github_branch_protection.go b/github/migrate_github_branch_protection.go index 02c537a5a5..67caa68df0 100644 --- a/github/migrate_github_branch_protection.go +++ b/github/migrate_github_branch_protection.go @@ -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{ @@ -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 }