Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on BranchProtection resource #7112

Closed
katietrant opened this issue May 21, 2021 · 7 comments
Closed

Error on BranchProtection resource #7112

katietrant opened this issue May 21, 2021 · 7 comments
Assignees
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/go needs-repro Needs repro steps before it can be triaged or fixed resolution/no-repro This issue wasn't able to be reproduced size/S Estimated effort to complete (1-2 days).
Milestone

Comments

@katietrant
Copy link

katietrant commented May 21, 2021

Expected behavior

pulumi imports BranchProtection resource after retrieval without error

Current behavior

Errors on import. Subsequent import fails on preview as it is already imported

Steps to reproduce

  1. run pulumi import github:index/branchProtection:BranchProtection repo.repo repo.repo:development
  2. agree to import

Stack Trace and relevant info

Pulumi Version:   v3.3.0
Go Version:       go1.16.3
Go Compiler:      gc
Architecture:     amd64
Operating System: darwin
Panic:            invalid Go source code:

package main

import (

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi-github/sdk/v4/go/github"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := github.NewBranchProtection(ctx, "repo_repo", &github.BranchProtectionArgs{
AllowsDeletions: pulumi.Bool(false),
AllowsForcePushes: pulumi.Bool(false),
EnforceAdmins: pulumi.Bool(false),
Pattern: pulumi.String("development"),
PushRestrictions: interface{}{
nil,
nil,
pulumi.String("MDQ6VGVhbTQwMjg0ODk="),
},
RepositoryId: pulumi.String("MDEwOlJlcG9zaXRvcnkyMTg4MzY5NDY="),
RequireSignedCommits: pulumi.Bool(false),
}, pulumi.Protect(true))
if err != nil {
return err
}
return nil
})
}


goroutine 1 [running]:
runtime/debug.Stack(0xc002212a88, 0x56d7840, 0xc000d0bd28)
	/usr/local/Cellar/go/1.16.3/libexec/src/runtime/debug/stack.go:24 +0x9f
main.panicHandler()
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/cmd/pulumi/main.go:29 +0x76
panic(0x56d7840, 0xc000d0bd28)
	/usr/local/Cellar/go/1.16.3/libexec/src/runtime/panic.go:965 +0x1b9
github.com/pulumi/pulumi/pkg/v3/codegen/go.GenerateProgram(0xc000ec1800, 0x691f620, 0xc001125ce0, 0x53a15c0, 0xc002cbada0, 0x1, 0x1)
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/codegen/go/gen_program.go:92 +0x91f
main.generateImportedDefinitions.func1(0x5c956c0, 0xc0008aad20, 0xc000ec1800, 0xc002212e00, 0x2)
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/cmd/pulumi/import.go:238 +0x44
github.com/pulumi/pulumi/pkg/v3/codegen/importer.GenerateLanguageDefinitions(0x5c956c0, 0xc0008aad20, 0x5c98020, 0xc000d56330, 0xc002213048, 0xc000722350, 0x1, 0x1, 0xc0008aad50, 0x27, ...)
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/codegen/importer/language.go:107 +0x5e9
main.generateImportedDefinitions(0x5c956c0, 0xc0008aad20, 0xc0005417a0, 0x6, 0xc000541010, 0x6, 0xc001af2f30, 0x59e2058, 0xc0008aad50, 0xc000537860, ...)
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/cmd/pulumi/import.go:237 +0x5a5
main.newImportCmd.func1(0xc0008adb80, 0xc0008aacc0, 0x3, 0x3, 0x0, 0x0)
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/cmd/pulumi/import.go:477 +0xed2
github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil.RunResultFunc.func1(0xc0008adb80, 0xc0008aacc0, 0x3, 0x3)
	/private/tmp/pulumi-20210520-6659-1j9ek9d/sdk/go/common/util/cmdutil/exit.go:112 +0x6b
github.com/spf13/cobra.(*Command).execute(0xc0008adb80, 0xc0008aac90, 0x3, 0x3, 0xc0008adb80, 0xc0008aac90)
	/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003a8000, 0xc00007c740, 0x406ddc8, 0xc000000180)
	/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
main.main()
	/private/tmp/pulumi-20210520-6659-1j9ek9d/pkg/cmd/pulumi/main.go:48 +0x4d
@katietrant katietrant added the kind/bug Some behavior is incorrect or out of spec label May 21, 2021
@lukehoban lukehoban added language/go area/codegen SDK-gen, program-gen, convert and removed kind/bug Some behavior is incorrect or out of spec labels May 28, 2021
@lukehoban
Copy link
Member

lukehoban commented May 28, 2021

This part doesn't look like legal Go code - so there is definitely something wrong in the Go codegen here:

PushRestrictions: interface{}{
nil,
nil,
pulumi.String("MDQ6VGVhbTQwMjg0ODk="),
},

We should understand whether this impacts only a corner case of pulumi import for Go, or impacts a common case. Marking as P1 as this is a panic, but if it's sufficiently corner case, we could demote from P1.

@lukehoban lukehoban added kind/bug Some behavior is incorrect or out of spec p1 Bugs severe enough to be the next item assigned to an engineer labels May 28, 2021
@lukehoban lukehoban added this to the 0.57 milestone May 28, 2021
@lukehoban lukehoban added the impact/panic This bug represents a panic or unexpected crash label May 28, 2021
@leezen leezen assigned komalali and unassigned t0yv0 Jun 7, 2021
@leezen leezen modified the milestones: 0.57, 0.58 Jun 7, 2021
@komalali
Copy link
Member

komalali commented Jun 8, 2021

Unfortunately, I can't repro this exact issue because PushRestrictions are only allowed on repos owned by an organization using Github Team or Github Enterprise Cloud (which my personal github account is not).

But, the correct code here should be (I think):

PushRestrictions: pulumi.StringArray{
	pulumi.String("MDQ6VGVhbTQwMjg0ODk="),
},

It doesn't look like this is an issue with go programgen in general, since the BranchProtection API docs have an example where this is generated correctly.

Unfortunately I have very low context on the inner workings of import, but I'll keep digging.

@EvanBoyle
Copy link
Contributor

The panic is due to generating invalid go source code. Other generators like the docs/examples generator catch panics from the codegens and report diagnostics at the end of a run. We should probably use the code generators in a similar manner within the import command.

if err != nil {
panic(errors.Errorf("invalid Go source code:\n\n%s", index.String()))

@komalali
Copy link
Member

komalali commented Jun 8, 2021

@kateetrant could you do a pulumi stack export and tell me what your inputs look like for this resource? I'm mostly curious about the pushRestrictions property.

But yeah, I can at least make the fix of not panicking and providing a more useful error.

@emiliza emiliza added the size/S Estimated effort to complete (1-2 days). label Jun 11, 2021
@komalali
Copy link
Member

I've fixed the panic to provide a better error, but the underlying error in import remains. Removing the p1 label and we can come back to this (or someone with the right github access can maybe get a repro so we can track down the underlying issue).

@komalali komalali removed impact/panic This bug represents a panic or unexpected crash p1 Bugs severe enough to be the next item assigned to an engineer labels Jun 11, 2021
@emiliza emiliza added needs-repro Needs repro steps before it can be triaged or fixed resolution/no-repro This issue wasn't able to be reproduced labels Jun 23, 2021
@emiliza
Copy link
Contributor

emiliza commented Jun 23, 2021

@kateetrant closing this due to inactivity. We've gone ahead and fixed the panic to get a better error but still need repro steps to understand the underlying import issue. If this is still a problem please create a new issue and include the information requested by Komal. Thanks!

@emiliza emiliza closed this as completed Jun 23, 2021
@katietrant
Copy link
Author

Hey sorry I didn't see this earlier. I'm not sure the export would be of any use now. We deleted all the previous resources and now have the branchProtectionV3 resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/go needs-repro Needs repro steps before it can be triaged or fixed resolution/no-repro This issue wasn't able to be reproduced size/S Estimated effort to complete (1-2 days).
Projects
None yet
Development

No branches or pull requests

7 participants