Skip to content

Commit

Permalink
Patch BranchProtection state migration (#594)
Browse files Browse the repository at this point in the history
Fixes #586
  • Loading branch information
iwahbe authored Mar 6, 2024
1 parent e5ae40b commit 39cb3a4
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "upstream"]
path = upstream
url = https://github.com/integrations/terraform-provider-github.git
ignore = dirty
15 changes: 15 additions & 0 deletions patches/0001-fix-586.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/github/migrate_github_branch_protection.go b/github/migrate_github_branch_protection.go
index 2eccae49..42dcc1f2 100644
--- a/github/migrate_github_branch_protection.go
+++ b/github/migrate_github_branch_protection.go
@@ -64,7 +64,9 @@ func resourceGithubBranchProtectionUpgradeV1(_ context.Context, rawState map[str
var blocksCreations bool = false

if v, ok := rawState["blocks_creations"]; ok {
- blocksCreations = v.(bool)
+ // Equate type errors as false. This is a work-around for
+ // https://github.com/pulumi/pulumi-terraform-bridge/issues/1667.
+ blocksCreations, _ = v.(bool)
}

if v, ok := rawState["push_restrictions"]; ok {
5 changes: 4 additions & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module github.com/pulumi/pulumi-github/provider/v6

go 1.21

replace github.com/integrations/terraform-provider-github/v6 => ../upstream

require (
github.com/integrations/terraform-provider-github/v6 v6.0.1
github.com/integrations/terraform-provider-github/v6 v6.0.0 // => ../upstream
github.com/pulumi/providertest v0.0.10
github.com/pulumi/pulumi-terraform-bridge/v3 v3.76.0
github.com/pulumi/pulumi/sdk/v3 v3.107.0
)
Expand Down
2 changes: 0 additions & 2 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1776,8 +1776,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/integrations/terraform-provider-github/v6 v6.0.1 h1:TbxI6QY+n7CRgViF59oU2yG7IbJ/AYTj2EUXFNGutS4=
github.com/integrations/terraform-provider-github/v6 v6.0.1/go.mod h1:VnSPPT6yQ8v5cOThma91zb/MTu0BGw8mcl8nL9G9Nko=
github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9FCCAVRQ=
github.com/ionos-cloud/sdk-go/v6 v6.1.3/go.mod h1:Ox3W0iiEz0GHnfY9e5LmAxwklsxguuNFEUSu0gVRTME=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
Expand Down
195 changes: 195 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package github_test

import (
"context"
"testing"

"github.com/pulumi/providertest/replay"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"

github "github.com/pulumi/pulumi-github/provider/v6"
"github.com/pulumi/pulumi-github/provider/v6/pkg/version"
)

const repro586 = `[
{
"method": "/pulumirpc.ResourceProvider/Diff",
"request": {
"id": "BPR_kwDOLcEl984C1wZz",
"urn": "urn:pulumi:dev::ts::github:index/branchProtection:BranchProtection::debug-pulumi-github-protection",
"olds": {
"__meta": "{\"schema_version\":\"1\"}",
"allowsDeletions": false,
"allowsForcePushes": false,
"blocksCreations": false,
"enforceAdmins": true,
"forcePushBypassers": [],
"id": "BPR_kwDOLcEl984C1wZz",
"lockBranch": false,
"pattern": "main",
"pushRestrictions": [
"/iwahbe"
],
"repositoryId": "debug-pulumi-github",
"requireConversationResolution": false,
"requireSignedCommits": false,
"requiredLinearHistory": false,
"requiredPullRequestReviews": [
{
"dismissStaleReviews": true,
"dismissalRestrictions": [],
"pullRequestBypassers": [],
"requireCodeOwnerReviews": false,
"requireLastPushApproval": false,
"requiredApprovingReviewCount": 1,
"restrictDismissals": false
}
],
"requiredStatusChecks": []
},
"news": {
"__defaults": [
"allowsForcePushes",
"lockBranch",
"requireConversationResolution",
"requireSignedCommits",
"requiredLinearHistory"
],
"allowsDeletions": false,
"allowsForcePushes": false,
"enforceAdmins": true,
"lockBranch": false,
"pattern": "main",
"repositoryId": "debug-pulumi-github",
"requireConversationResolution": false,
"requireSignedCommits": false,
"requiredLinearHistory": false,
"requiredPullRequestReviews": [
{
"__defaults": [
"requireLastPushApproval"
],
"dismissStaleReviews": true,
"requireLastPushApproval": false,
"requiredApprovingReviewCount": 1
}
],
"restrictPushes": [
{
"__defaults": [
"blocksCreations"
],
"blocksCreations": true,
"pushAllowances": [
"/iwahbe"
]
}
]
},
"oldInputs": {
"__defaults": [
"allowsForcePushes",
"blocksCreations",
"lockBranch",
"requireConversationResolution",
"requireSignedCommits",
"requiredLinearHistory"
],
"allowsDeletions": false,
"allowsForcePushes": false,
"blocksCreations": false,
"enforceAdmins": true,
"lockBranch": false,
"pattern": "main",
"pushRestrictions": [
"/iwahbe"
],
"repositoryId": "debug-pulumi-github",
"requireConversationResolution": false,
"requireSignedCommits": false,
"requiredLinearHistory": false,
"requiredPullRequestReviews": [
{
"__defaults": [
"requireLastPushApproval"
],
"dismissStaleReviews": true,
"requireLastPushApproval": false,
"requiredApprovingReviewCount": 1
}
]
}
},
"response": {
"replaces": [
"repositoryId"
],
"changes": "DIFF_SOME",
"diffs": "*",
"detailedDiff": {
"allowsDeletions": {
"kind": "UPDATE"
},
"allowsForcePushes": {
"kind": "UPDATE"
},
"enforceAdmins": {
"kind": "UPDATE"
},
"lockBranch": {
"kind": "UPDATE"
},
"pattern": {
"kind": "UPDATE"
},
"repositoryId": {
"kind": "UPDATE_REPLACE"
},
"requireConversationResolution": {
"kind": "UPDATE"
},
"requireSignedCommits": {
"kind": "UPDATE"
},
"requiredLinearHistory": {
"kind": "UPDATE"
},
"requiredPullRequestReviews[0].dismissStaleReviews": {
"kind": "UPDATE"
},
"requiredPullRequestReviews[0].requireLastPushApproval": {
"kind": "UPDATE"
},
"requiredPullRequestReviews[0].requiredApprovingReviewCount": {
"kind": "UPDATE"
},
"restrictPushes[0].blocksCreations": {},
"restrictPushes[0].pushAllowances[0]": {}
},
"hasDetailedDiff": true
},
"metadata": {
"kind": "resource",
"mode": "client",
"name": "github"
}
}
]
`

func TestRepros(t *testing.T) {
t.Run("586", func(t *testing.T) {
replay.ReplaySequence(t, server(t), repro586)
})
}

func init() {
version.Version = "6.0.0"
}

func server(*testing.T) pulumirpc.ResourceProviderServer {
p := github.Provider()
return tfbridge.NewProvider(context.Background(),
nil, "github", version.Version, p.P, p, []byte("{}"))
}
8 changes: 6 additions & 2 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func Provider() tfbridge.ProviderInfo {
GitHubOrg: "integrations",
Version: version.Version,
MetadataInfo: tfbridge.NewProviderMetadata(metadata),
UpstreamRepoPath: "./upstream",
Config: map[string]*tfbridge.SchemaInfo{
"base_url": {
Default: &tfbridge.DefaultInfo{
Expand Down Expand Up @@ -115,8 +116,11 @@ func Provider() tfbridge.ProviderInfo {
},
},
},
"github_branch_default": {Tok: makeResource(mainMod, "BranchDefault")},
"github_branch_protection": {Tok: makeResource(mainMod, "BranchProtection")},
"github_branch_default": {Tok: makeResource(mainMod, "BranchDefault")},
"github_branch_protection": {
Tok: makeResource(mainMod, "BranchProtection"),
TransformFromState: nil,
},
"github_branch_protection_v3": {Tok: makeResource(mainMod, "BranchProtectionV3")},
"github_dependabot_organization_secret": {
Tok: makeResource(mainMod, "DependabotOrganizationSecret"),
Expand Down
1 change: 1 addition & 0 deletions upstream
Submodule upstream added at b9af9f

0 comments on commit 39cb3a4

Please sign in to comment.