Skip to content

Commit

Permalink
Fix golangci-lint failures
Browse files Browse the repository at this point in the history
- Fix config warnings, as backported into ci-mgmt: pulumi/ci-mgmt#1064
  - The configuration option run.skip-files is deprecated, please use issues.exclude-files.
  - The linter named "megacheck" is deprecated. It has been split into: gosimple, staticcheck, unused.
- Remove go:linkname which was added when we weren't maintaining patches and so had to use a compiler hack to set a value. This variable no longer exists so has no effect. Reported error:

    SA9009: ineffectual compiler directive due to extraneous space: "// go:linkname is not widely used outside the standard library, but allows us to" (staticcheck)
  • Loading branch information
danielrbradley committed Aug 29, 2024
1 parent 00003ba commit 6dd00ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
8 changes: 5 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ linters:
- govet
- ineffassign
- lll
- megacheck
- gosimple
- staticcheck
- misspell
- nakedret
- revive
- unconvert
- unused
enable-all: false
run:
skip-files:
issues:
exclude-files:
- schema.go
- pulumiManifest.go
run:
timeout: 20m
linters-settings:
gci:
Expand Down
40 changes: 0 additions & 40 deletions provider/cmd/pulumi-resource-azure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,13 @@ package main

import (
_ "embed"
_ "unsafe" // Import go:linkname

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

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

// The AzureRM Terraform Provider has a setting named ARM_PROVIDER_STRICT, the bulk
// of which was introduced into terraform-providers/terraform-provider-azurerm in commit
// 447abecad. The setting prevents accidental adoption of existing resources, and is
// something we want to opt into - not delegate to user control via the environment.
//
// When we maintained our own fork of terraform-providers-azurerm, we just enabled the
// setting by modifying the feature flag value directly. Sadly it is unexported, and now
// we do _not_ depend on a fork but on upstream directly, we need a way to set that.
//
// One option would be to use os.Setenv to set the environment variable for the child
// processes - but this would put Azure specific bits into the plugin loader which is
// not desirable. Instead, we use `go:linkname` to make the private package-level variable
// which controls this behaviour accessible to us.
//
// go:linkname is not widely used outside the standard library, but allows us to
// effectively alias a particular symbol via an accessible name. Per Ian Lance Taylor's
// post on golang-dev [1], "it means: every time you are about to write out X in the object
// file, write out Y instead."
//
// So, by aliasing a local variable `strictMode` to the particular symbol in question in
// the azure provider (identified via `nm`), we can set the private value here by assigning
// our own `strictMode` variable. Note that since we build with the vendor/ directory, we
// must use the qualified vendor path to the symbol.
//
// Unfortunately, `go:linkname` does not give an error if the symbol being aliased does
// not exist. Since we are aliasing into someone elses package, there is a real risk that
// an upstream refactor will move or break this variable. To that end, as part of the lint
// step in Makefile, we verify that the built binary actually has the symbol listed here
// present. This does not protect against behavioural change, but we can likely write a
// test for the undesirable behaviour to validate against that.
//
// Changes to this area of code are noted for upstream v1.30.0 (we are adopting this at
// v1.29.0) but do not affect the way we need to handle this.
//
// [1]: https://groups.google.com/forum/#!topic/golang-dev/j2r7Vq6CBZk

//nolint:lll
//go:linkname strictMode github.com/pulumi/pulumi-azure/vendor/github.com/terraform-providers/terraform-provider-azurerm/azurerm.requireResourcesToBeImported

//go:embed schema-embed.json
var pulumiSchema []byte

Expand Down

0 comments on commit 6dd00ea

Please sign in to comment.