[PATCH] Add terraform and terraform-provider-libvirt

OpenSubmitted by Christopher Baines.
Details
3 participants
  • Chris Marusich
  • Pierre Neidhardt
  • Christopher Baines
Owner
unassigned
Severity
normal
C
C
Christopher Baines wrote on 13 Mar 2018 21:25
(address . guix-patches@gnu.org)
87y3ivzps1.fsf@cbaines.net
Tags: moreinfo
I'll send some patches for adding a Terraform package and the Terraformlibvirt provider. Both of these work, at least in the way I've beenusing them, but the packages need more work before they can beincluded. I think both packages include quite a few copies of otherlibraries which need packaging for Guix.

Christopher Baines (2): gnu: Add terraform. gnu: Add terraform-provider-libvirt.
gnu/local.mk | 1 + gnu/packages/terraform.scm | 106 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 gnu/packages/terraform.scm
-----BEGIN PGP SIGNATURE-----
iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlqoM75fFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNFODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE9Xd30w//WWKK9xQ6TbalXF6UBsPPgQ1iRfGBFaObwfnAhtxviHxehGE2vXAQpLmKoc0mcdwVe7A+Ln0TnhPv7hq+KZRJCqcRGRkoVspJB2kb+vUCGVsbPqU5bCoQP3WBk4lVqf7TeMlseFY4lR66x3Jx5SxjeS5A9jJSBOsPXpmKI/5oVb3ZreRrpGtzrm8cgKC84jN8xUYYsU9PZGSjmDcnOutf/YJzwD+rdgV4BCruFQg5WbzYdJw7gyBUqx3A5gQek6l0AztPGXSy/+ytKC1kiD+V6DjDJkEhe0pkiH9EJnYeAR0f1AZ8pmq78WnzxPHKdvmFA6xULEE8TRyX5xppk6KFHZaC7mv4jIil5MSPZ3NIZtMUvoCoBi3hu6IWVLalKWay5EvcKcJr3m/c7mdADLzsYrvrGK4mOFmR07ur3iQrchJ8IeVV3je7oNFlvTN8JlHUjCdrN4HdBmQfLehDHU17erwSO7ZlT0DMsE0p1b9Nx4aCWn0CpaeY43McxFuyt5jrdET41gageO39rHAybf9SKhTLmcGkdZzTQbi76lp2OT2FIB1bxnrrm7vme/8NrRhUKXsdDl4B2I/7Cop+RCtiqKRuFEblDsQbcxUwcEwnr4ekFoR0wTLIA4O8iw5kw3D+zAw3FEvpD4vBDncaqsJlBG2MCCufqYyXH/KmYPG+6CU==4qAe-----END PGP SIGNATURE-----
C
C
Christopher Baines wrote on 13 Mar 2018 21:30
[PATCH 2/2] gnu: Add terraform-provider-libvirt.
(address . 30806@debbugs.gnu.org)
20180313203008.3487-2-mail@cbaines.net
* gnu/packages/terraform.scm (terraform-provider-libvirt): New variable.--- gnu/packages/terraform.scm | 48 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
Toggle diff (65 lines)diff --git a/gnu/packages/terraform.scm b/gnu/packages/terraform.scmindex 277d19aed..e81ada45d 100644--- a/gnu/packages/terraform.scm+++ b/gnu/packages/terraform.scm@@ -21,7 +21,11 @@ #:use-module (guix packages) #:use-module (guix download) #:use-module (guix git-download)- #:use-module (guix build-system go))+ #:use-module (guix build-system go)+ #:use-module (gnu packages golang)+ #:use-module (gnu packages cdrom)+ #:use-module (gnu packages pkg-config)+ #:use-module (gnu packages virtualization)) (define-public terraform (package@@ -58,3 +62,45 @@ apply changes to the described resources. Terraform uses plugins that provide intergrations to different providers.") (home-page "https://www.terraform.io/") (license license:mpl2.0)))++(define-public terraform-provider-libvirt+ (package+ (name "terraform-provider-libvirt")+ (version "0.3")+ (source (origin+ (method git-fetch)+ (uri (git-reference+ (url "https://github.com/dmacvicar/terraform-provider-libvirt")+ (commit (string-append "v" version))))+ (sha256+ (base32+ "004gxy55p5cf39f2zpah0i2zhvs4x6ixnxy8z9v7314604ggpkna"))))+ (build-system go-build-system)+ (native-inputs+ `(("pkg-config" ,pkg-config)))+ (inputs+ `(("libvirt" ,libvirt)+ ("cdrtools" ,cdrtools)))+ (arguments+ '(#:import-path "github.com/dmacvicar/terraform-provider-libvirt"+ #:phases+ (modify-phases %standard-phases+ (add-after 'unpack 'patch-mkisofs+ (lambda* (#:key inputs #:allow-other-keys)+ (substitute*+ "src/github.com/dmacvicar/terraform-provider-libvirt/libvirt/cloudinit_def.go"+ (("mkisofs")+ (string-append (assoc-ref inputs "cdrtools")+ "/bin/mkisofs")))))+ ;; This should be redundant once the vendor directory is removed from+ ;; this package+ (add-before 'reset-gzip-timestamps 'remove-readonly-gzip-files+ (lambda* (#:key outputs #:allow-other-keys)+ (for-each delete-file+ (find-files+ (assoc-ref outputs "out")+ ".*\\.gz")))))))+ (synopsis "")+ (description "")+ (home-page "")+ (license "")))-- 2.16.2
C
C
Christopher Baines wrote on 13 Mar 2018 21:30
[PATCH 1/2] gnu: Add terraform.
(address . 30806@debbugs.gnu.org)
20180313203008.3487-1-mail@cbaines.net
* gnu/packages/terraform.scm (New file).* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.--- gnu/local.mk | 1 + gnu/packages/terraform.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 gnu/packages/terraform.scm
Toggle diff (80 lines)diff --git a/gnu/local.mk b/gnu/local.mkindex 5a3ae502f..2b5502e8e 100644--- a/gnu/local.mk+++ b/gnu/local.mk@@ -410,6 +410,7 @@ GNU_SYSTEM_MODULES = \ %D%/packages/tcl.scm \ %D%/packages/telephony.scm \ %D%/packages/terminals.scm \+ %D%/packages/terraform.scm \ %D%/packages/texinfo.scm \ %D%/packages/tex.scm \ %D%/packages/textutils.scm \diff --git a/gnu/packages/terraform.scm b/gnu/packages/terraform.scmnew file mode 100644index 000000000..277d19aed--- /dev/null+++ b/gnu/packages/terraform.scm@@ -0,0 +1,60 @@+;;; GNU Guix --- Functional package management for GNU+;;; Copyright © 2018 Christopher Baines <mail@cbaines.net>+;;;+;;; This file is part of GNU Guix.+;;;+;;; GNU Guix is free software; you can redistribute it and/or modify it+;;; under the terms of the GNU General Public License as published by+;;; the Free Software Foundation; either version 3 of the License, or (at+;;; your option) any later version.+;;;+;;; GNU Guix is distributed in the hope that it will be useful, but+;;; WITHOUT ANY WARRANTY; without even the implied warranty of+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+;;; GNU General Public License for more details.+;;;+;;; You should have received a copy of the GNU General Public License+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.++(define-module (gnu packages terraform)+ #:use-module ((guix licenses) #:prefix license:)+ #:use-module (guix packages)+ #:use-module (guix download)+ #:use-module (guix git-download)+ #:use-module (guix build-system go))++(define-public terraform+ (package+ (name "terraform")+ (version "0.11.3")+ (source (origin+ (method git-fetch)+ (uri (git-reference+ (url "https://github.com/hashicorp/terraform")+ (commit (string-append "v" version))))+ (sha256+ (base32+ "0637x7jcm62pdnivmh4rggly6dmlvdh3jpsd1z4vba15gbm203nz"))))+ (build-system go-build-system)+ (arguments+ '(#:import-path "github.com/hashicorp/terraform"+ #:phases+ (modify-phases %standard-phases+ ;; I'm not sure what purpose they serve, but they are readonly, so+ ;; they break the reset-gzip-timestamps phase.+ (add-after 'install 'delete-test-fixtures+ (lambda* (#:key outputs #:allow-other-keys)+ (delete-file-recursively+ (string-append+ (assoc-ref outputs "out")+ "/src/github.com/hashicorp/terraform/config/module/test-fixtures")))))))+ (synopsis "Tool for building and changing computing infrastructure")+ (description+ "Terraform uses descriptions of infrastructure written in @acronym{HCL,+Hashicorp Configuration Language} which describe graphs of resources,+including information about dependencies. From this, Terraform can plan and+apply changes to the described resources.++Terraform uses plugins that provide intergrations to different providers.")+ (home-page "https://www.terraform.io/")+ (license license:mpl2.0)))-- 2.16.2
C
C
Chris Marusich wrote on 20 Dec 2018 10:31
Re: Packaging Terraform, a Golang package
87bm5g4k8r.fsf@gmail.com
Hello Chris and Pierre!
Thank you for your tips regarding Golang and Terraform. I've built it -both ad-hoc and using a slightly modified version of Chris' originalpackage definition. I'm still getting used to Golang's build system andour own golang-build-system, so please bear with me!
I was able to run the official Terraform build steps on the latestTerraform release by issuing the following commands - but I'm not sureif this actually produced the terraform program:
mkdir terraformcd terraform/wget https://github.com/hashicorp/terraform/archive/v0.11.11.tar.gztar -xf v0.11.11.tar.gzmkdir -p src/github.com/hashicorpcp -r terraform-0.11.11 src/github.com/hashicorp/terraformguix package -i go make git bash grep findutils which coreutils diffutils -p .guix-profilemkdir gobineval "$(guix package --search-paths=exact --profile=$(realpath --no-symlinks .guix-profile))"export GOPATH="$(pwd)"export GOBIN="$GOPATH/bin"export PATH="$PATH:$GOBIN"cd src/github.com/hashicorp/terraform/make toolsmake
Those last two commands are the ones listed in Terraform's README.md.It looks like the final command, "make" will execute the "fmtcheck","generate", and "test" recipes in that order. Here are the relevantparts of the Makefile:
Toggle snippet (27 lines)default: test
[...]
# test runs the unit tests# we run this one package at a time here because running the entire suite in# one command creates memory usage issues when running in Travis-CI.test: fmtcheck generate go list $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=2m -parallel=4
[...]
# generate runs `go generate` to build the dynamically generated# source files.generate: @which stringer > /dev/null; if [ $$? -ne 0 ]; then \ go get -u golang.org/x/tools/cmd/stringer; \ fi go generate ./... @go fmt command/internal_plugin_list.go > /dev/null
[...]
fmtcheck: @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
So, in essence this runs "go generate", "go fmt", and "go test". Thescript gofmtcheck.sh seems to be a read-only linter to assist theTerraform maintainers in finding badly formatted Golang files.
This is slightly different from the installation procedure that ourgo-build-system runs. When you build the attached package (whichpackages an older version of terraform for now), our go-build-systemruns steps like the following (in order from top to bottom):
* Phase: unpack: Make a "src/github.com/hashicorp/terraform" directory.* Phase: setup-environment: set GOPATH to (getcwd) and GOBIN to $out/bin.* Phase: build: go install -v -x '-ldflags=-s -w' github.com/hashicorp/terraform* Phase: check: go test github.com/hashicorp/terraform
All in all, this has raised some questions in my mind:
1) Is it bad that our package definition isn't running "go generate" or"go fmt"? Do you know if "go install" does this for us somehow? Idon't think "stringer" or "mockgen" are present in the buildenvironment, but our "go install" invocation seems to build terraformeven without them. I wonder if the built terraform is broken in someways because we didn't run the code generation/formatting steps.
2) After I ran "make" ad-hoc, I couldn't find a built "terraform"executable anywhere. Where is it? Am missing something obvious, orcould it be that the official documentation incomplete and I need to askupstream for advice?
3) The official instructions seem to arbitrarily choose to run the buildin parallel, using 4 threads, which means this package won't play nicewith build arguments like --cores. I suppose I might need to work withupstream to fix that.
This feels so close, and yet so far. Hopefully we only have a littlemore to do to get Terraform packaged well! Thank you again for yourhelp.
-- Chris
From 71d654e2738c6ef870441d4234632bd30e93c74a Mon Sep 17 00:00:00 2001From: Chris Marusich <cmmarusich@gmail.com>Date: Thu, 20 Dec 2018 01:24:59 -0800Subject: [PATCH] gnu: Add terraform.
This patch is slightly modified from Christopher Baines' original patch toaccommodate some changes that have taken place recently in the Guix sourcetree. But it's essentially the same. It is still probably not suitable forinclusion in Guix just yet.
* gnu/packages/terraform.scm (terraform): New variable.--- gnu/packages/terraform.scm | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
Toggle diff (50 lines)diff --git a/gnu/packages/terraform.scm b/gnu/packages/terraform.scmindex f14b152fd..de2288dda 100644--- a/gnu/packages/terraform.scm+++ b/gnu/packages/terraform.scm@@ -47,3 +47,43 @@ the inputs and outputs for modules of the Terraform infrastructure management tool. These can be shown, or written to a file in JSON or Markdown formats.") (home-page "https://github.com/segmentio/terraform-docs") (license license:expat)))++(define-public terraform+ (package+ (name "terraform")+ (version "0.11.3")+ (source (origin+ (method git-fetch)+ (uri (git-reference+ (url "https://github.com/hashicorp/terraform")+ (commit (string-append "v" version))))+ (sha256+ (base32+ "0637x7jcm62pdnivmh4rggly6dmlvdh3jpsd1z4vba15gbm203nz"))))+ (build-system go-build-system)+ (arguments+ '(#:import-path "github.com/hashicorp/terraform"+ #:phases+ (modify-phases %standard-phases+ ;; I'm not sure what purpose they serve, but they are readonly, so+ ;; they break the reset-gzip-timestamps phase.+ (add-after 'install 'delete-test-fixtures+ (lambda* (#:key outputs #:allow-other-keys)+ ;; If delete-file-recursively fails, it won't throw an exception.+ ;; However, if it doesn't do its job, the build will fail, so+ ;; we'll know one way or another.+ (delete-file-recursively+ (string-append+ (assoc-ref outputs "out")+ "/src/github.com/hashicorp/terraform/config/module/test-fixtures"))+ #t)))))+ (synopsis "Tool for building and changing computing infrastructure")+ (description+ "Terraform uses descriptions of infrastructure written in @acronym{HCL,+Hashicorp Configuration Language} which describe graphs of resources,+including information about dependencies. From this, Terraform can plan and+apply changes to the described resources.++Terraform uses plugins that provide intergrations to different providers.")+ (home-page "https://www.terraform.io/")+ (license license:mpl2.0)))-- 2.20.0
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCAAdFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAlwbYYQACgkQ3UCaFdgiRp2pVRAAldIZ7HMppNLV19sT0R8pJuFL9MdlTAXrfus1PORIpXXsDyCSbJdkkCgU0YBSCXMma91dPcABegKNbsN5WdztwMNd1/LailLSTnAQa7NFxAZTKOlrATtq+hY1aqnUiaTkFSMQ+OKnCPrDJ8DLFqic1HOr72qeHlSu/dMYg5e14bDZQTlm2Z1MV28hOhwevOozyVu7L3mJL/I839U8ysIyEnq3AB+q/+XHn7mwfY727uxM4GNVUzETvJAlOiJTiqxES2Lyit14JHmKIol+lJGD4G2+659n3prodq4g1m0M9Ec0BV4urX1xEaHte9Aafe0Rx9D7nnRze8L/HNwI8IKS/XmUqBvPWHAAq5IIePAagq3Zvo2BDVYfZFe8nDcdgB0ViM/mNUa0n7eU7zRAnwcun+Z5DFJCllpkiMNTDr4l57LNnJXuzCuCcSGT3OHvnUvY7Rgrordhdgv/tSaEM+4L+8GCSptIImW2WNq9aWjURKlOemjitSQCF2kgU8OVM1NoLY4xCFsCyXSA4TXKgKsUuo8bgbTclP7ofYBMKQuEm+aaI4XT2tOhGBAgu4EjBxCR8vreJJob//+CxCr2YzlYvBWvkJPBGNlFgEQj+NOPRRR1ScKDUTxhwbarxPFXrSfIjLUTKGOwEpecKV12WjQI1UL9XKe7J1hwJ4C8rC7ZRJY==qchI-----END PGP SIGNATURE-----
P
P
Pierre Neidhardt wrote on 20 Dec 2018 10:47
(name . Chris Marusich)(address . cmmarusich@gmail.com)
87woo4zg0p.fsf@ambrevar.xyz
Toggle quote (4 lines)> 1) Is it bad that our package definition isn't running "go generate" or> "go fmt"? Do you know if "go install" does this for us somehow? I> don't think "stringer" or "mockgen" are present in the build
"go generate" is used to generate code, it's like a preprocessor. Most Goprograms don't use it, but if they do, then it's needed.
"go fmt" should not be part of the build process in my opinion. A codeformatter fits better into a Git hook or something.
Toggle quote (5 lines)> 2) After I ran "make" ad-hoc, I couldn't find a built "terraform"> executable anywhere. Where is it? Am missing something obvious, or> could it be that the official documentation incomplete and I need to ask> upstream for advice?
I haven't looked into it, but it should be either in ~/go/bin or in the packagesource folder, something like ~/go/src/.../terraform/.
Toggle quote (5 lines)> 3) The official instructions seem to arbitrarily choose to run the build> in parallel, using 4 threads, which means this package won't play nice> with build arguments like --cores. I suppose I might need to work with> upstream to fix that.
I think Go decides this on its own. Off the top of my head, there is anenvironment variable to control the number of CPU threads used globally,GO_xxx_CORES or something like that.
-- Pierre Neidhardthttps://ambrevar.xyz/
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlwbZSYACgkQm9z0l6S7zH+4+wgAqodcAcZ28ZHf8W9KaeUXwsffaoqr19e1Gixwc8enb2X61YyG/TZYUp/jICfXe7xzjm8n4uKmSjYa8Te17bVR+tfEEDEq8wJoBBlCFS60kIXSFfGPw4qFPmm4+0q4BB/CKmh75nmL6K2UYPwOViHHuSezd5mXk1CYbvA00KqFNw/+hz7DcNhK4XsBLkSxYSux5CwGaZdWYi8lRStBChkeIW52N4BurAj5CpGzG9KxJ70plF00bhq4paKMt8db2G+YR0cvE3STdf4GbZ+TYVBgat9BfnY7iOBh7Ju7nyjdJ+rvcaOj2LBLHccz7IyAvZizAscQCJ2w6oWyksKSs2YUfQ===ddux-----END PGP SIGNATURE-----
?