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

terraform-providers: build automated providers with Go module #103822

Merged

Conversation

timstott
Copy link
Contributor

@timstott timstott commented Nov 14, 2020

Motivation for this change

With more providers adopting Go module, nixpkgs needs to follow suit. This work adds a vendorSha256 key to providers that use Go module. When the key is present the provider will be built with Go module, else with Go package.

The update-provider script has been updated to handle vendorSha256 and will be made available in a subsequent PR.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot requested a review from kalbasit November 14, 2020 17:19
@timstott timstott force-pushed the timstott/terraform-providers-go-module-support branch 2 times, most recently from ee45748 to 2fb7726 Compare November 19, 2020 09:18
@timstott timstott marked this pull request as ready for review November 19, 2020 09:19
@timstott
Copy link
Contributor Author

✔️ Successful provider initialization with

  • terraform_0_11
  • terraform_0_12
  • terraform_0_13
# main.tf
terraform {
  required_providers {
    ibm = {
      source = "IBM-Cloud/ibm"
    }
    digitalocean = {
      source = "digitalocean/digitalocean"
    }
  }
}

provider "aws" {}
provider "dns" {}
provider "random" {}
provider "null" {}
provider "tls" {}
provider "template" {}
provider "local" {}
provider "http" {}
provider "archive" {}
provider "external" {}
provider "google" {}
provider "google-beta" {}
provider "digitalocean" {}
provider "ibm" {}
provider "helm" {}
$ nix-shell -I nixpkgs=$PWD -p 'terraform_0_13.withPlugins (p : with p; [aws dns random tls template local http archive external google google-beta digitalocean ibm helm] ++ [p.null])'
$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/external...
- Finding latest version of hashicorp/local...
- Finding latest version of ibm-cloud/ibm...
- Finding latest version of hashicorp/aws...
- Finding latest version of hashicorp/http...
- Finding latest version of hashicorp/null...
- Finding latest version of digitalocean/digitalocean...
- Finding latest version of hashicorp/tls...
- Finding latest version of hashicorp/archive...
- Finding latest version of hashicorp/random...
- Finding latest version of hashicorp/dns...
- Finding latest version of hashicorp/google-beta...
- Finding latest version of hashicorp/helm...
- Finding latest version of hashicorp/template...
- Finding latest version of hashicorp/google...
- Installing digitalocean/digitalocean v2.2.0...
- Installed digitalocean/digitalocean v2.2.0 (unauthenticated)
- Installing hashicorp/local v2.0.0...
- Installed hashicorp/local v2.0.0 (unauthenticated)
- Installing hashicorp/aws v3.15.0...
- Installed hashicorp/aws v3.15.0 (unauthenticated)
- Installing hashicorp/random v3.0.0...
- Installed hashicorp/random v3.0.0 (unauthenticated)
- Installing hashicorp/http v2.0.0...
- Installed hashicorp/http v2.0.0 (unauthenticated)
- Installing hashicorp/archive v2.0.0...
- Installed hashicorp/archive v2.0.0 (unauthenticated)
- Installing hashicorp/dns v3.0.0...
- Installed hashicorp/dns v3.0.0 (unauthenticated)
- Installing hashicorp/template v2.2.0...
- Installed hashicorp/template v2.2.0 (unauthenticated)
- Installing hashicorp/google v3.47.0...
- Installed hashicorp/google v3.47.0 (unauthenticated)
- Installing ibm-cloud/ibm v1.14.0...
- Installed ibm-cloud/ibm v1.14.0 (unauthenticated)
- Installing hashicorp/tls v3.0.0...
- Installed hashicorp/tls v3.0.0 (unauthenticated)
- Installing hashicorp/google-beta v3.47.0...
- Installed hashicorp/google-beta v3.47.0 (unauthenticated)
- Installing hashicorp/helm v1.3.2...
- Installed hashicorp/helm v1.3.2 (unauthenticated)
- Installing hashicorp/external v2.0.0...
- Installed hashicorp/external v2.0.0 (unauthenticated)
- Installing hashicorp/null v3.0.0...
- Installed hashicorp/null v3.0.0 (unauthenticated)

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* digitalocean/digitalocean: version = "~> 2.2.0"
* hashicorp/archive: version = "~> 2.0.0"
* hashicorp/aws: version = "~> 3.15.0"
* hashicorp/dns: version = "~> 3.0.0"
* hashicorp/external: version = "~> 2.0.0"
* hashicorp/google: version = "~> 3.47.0"
* hashicorp/google-beta: version = "~> 3.47.0"
* hashicorp/helm: version = "~> 1.3.2"
* hashicorp/http: version = "~> 2.0.0"
* hashicorp/local: version = "~> 2.0.0"
* hashicorp/null: version = "~> 3.0.0"
* hashicorp/random: version = "~> 3.0.0"
* hashicorp/template: version = "~> 2.2.0"
* hashicorp/tls: version = "~> 3.0.0"
* ibm-cloud/ibm: version = "~> 1.14.0"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although, these seem to build fine

https://github.com/NixOS/nixpkgs/pull/103822
19 packages built:
terraform-full terraform-providers.archive terraform-providers.aws terraform-providers.digitalocean terraform-providers.dns terraform-providers.external terraform-providers.google terraform-providers.google-beta terraform-providers.helm terraform-providers.http terraform-providers.ibm terraform-providers.local terraform-providers.null terraform-providers.random terraform-providers.template terraform-providers.tls terraform_0_11-full terraform_plugins_test terragrunt

Comment on lines 44 to 45
(if attrs ? vendorSha256 then buildWithGoModule else buildWithGoPackage)
name attrs) list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right. shouldn't it be:

Suggested change
(if attrs ? vendorSha256 then buildWithGoModule else buildWithGoPackage)
name attrs) list;
(if (lib.hasAttr "vendorSha256" attrs) then buildWithGoModule else buildWithGoPackage)
name attrs) list;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some legit nix (source) 😉

image

More than happy to use the lib.hasAttr function instead of the ? operator if that is the preferred way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, well it seemed to have the expected behavior, but I think lib.hasAttr is more readable. and isn't contextual like ? which can also be used to provide a default value when inside an attrset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the function is the least ambiguous of the two. Fixed it now.

@timstott timstott force-pushed the timstott/terraform-providers-go-module-support branch from 2fb7726 to 16e5e12 Compare November 19, 2020 23:01
@@ -7,7 +8,23 @@
let
list = lib.importJSON ./providers.json;

toDrv = name: data:
buildWithGoModule = name: data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is not used. Am I missing something? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent spot, fixed in both buildWithGoModule and buildWithGoPackage 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kalbasit would you be able to give this a once over. I've address all outstanding comments 🙇

@timstott timstott force-pushed the timstott/terraform-providers-go-module-support branch from 16e5e12 to 0c76f11 Compare November 20, 2020 07:43
@timstott timstott force-pushed the timstott/terraform-providers-go-module-support branch from 0c76f11 to 61ebe1f Compare November 20, 2020 07:55
Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'll defer to @kalbasit on go packaging

https://github.com/NixOS/nixpkgs/pull/103822
19 packages built:
terraform-full terraform-providers.archive terraform-providers.aws terraform-providers.digitalocean terraform-providers.dns terraform-providers.external terraform-providers.google terraform-providers.google-beta terraform-providers.helm terraform-providers.http terraform-providers.ibm terraform-providers.local terraform-providers.null terraform-providers.random terraform-providers.template terraform-providers.tls terraform_0_11-full terraform_plugins_test terragrunt

"version": "2.65.0"
"rev": "v3.15.0",
"sha256": "0rxpdxg5p478sipbhq2x347gs5wrlwz4ggy9z007cbp34yhb2wka",
"vendorSha256": "0vapfnd4c8jb15pdjnnb97vgsvfakjvl1czccbfy0znhdk2ynz02",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would one update this? Shouldn't the update-provider script be updated to take care of that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that is the intention, I have a PR that needs a little more work #104696.

The aim is to hook it up to updateScript

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allright then, I think this PR is good to go.

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Result of nixpkgs-review pr 103822 1

19 packages built:
  • terraform-full
  • terraform-providers.archive
  • terraform-providers.aws
  • terraform-providers.digitalocean
  • terraform-providers.dns
  • terraform-providers.external
  • terraform-providers.google
  • terraform-providers.google-beta
  • terraform-providers.helm
  • terraform-providers.http
  • terraform-providers.ibm
  • terraform-providers.local
  • terraform-providers.null
  • terraform-providers.random
  • terraform-providers.template
  • terraform-providers.tls
  • terraform_0_11-full
  • terraform_plugins_test
  • terragrunt

@jonringer jonringer merged commit 0fb14ea into NixOS:master Nov 24, 2020
@flokli
Copy link
Contributor

flokli commented Nov 24, 2020

Oof, not sure if this should have been merged, given the update-provider script is still missing, and both are included in #104667

@flokli
Copy link
Contributor

flokli commented Nov 24, 2020

We should really try to get a full updater story into nixpkgs.

@timstott timstott deleted the timstott/terraform-providers-go-module-support branch November 24, 2020 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants