GithubHelp home page GithubHelp logo

dpires / jenkins-terraform-plugin Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 39.0 144 KB

A Jenkins plugin that installs Terraform and provides a build wrapper for launching infrastructure

License: MIT License

Java 83.88% Groovy 8.34% HTML 7.78%

jenkins-terraform-plugin's People

Contributors

dpires avatar jambit-admin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jenkins-terraform-plugin's Issues

Jenkins Pipeline 'tool' step not installing Terraform automatically (1.0.8)

After configuring the terraform tool, the resulting XML is the following:

<?xml version='1.0' encoding='UTF-8'?>
<org.jenkinsci.plugins.terraform.TerraformBuildWrapper_-DescriptorImpl plugin="[email protected]">
 <installations>
   <org.jenkinsci.plugins.terraform.TerraformInstallation>
     <name>Terraform 0.7.8</name>
     <home>/var/jenkins_home//terraform_0.7.8_linux_amd64</home>
     <properties>
       <hudson.tools.InstallSourceProperty>
         <installers>
           <org.jenkinsci.plugins.terraform.TerraformInstaller>
             <id>0.7.8-linux-amd64</id>
           </org.jenkinsci.plugins.terraform.TerraformInstaller>
         </installers>
       </hudson.tools.InstallSourceProperty>
     </properties>
   </org.jenkinsci.plugins.terraform.TerraformInstallation>
 </installations>
</org.jenkinsci.plugins.terraform.TerraformBuildWrapper_-DescriptorImpl>

This seems fine, however when using the "tool" pipeline step the terraform binary is not installed automatically.

I've also tried creating a freestyle job and selecting the terraform option on the "Build Environment" section, and that works ok.

How can we make this work with the jenkins pipelines?

terraform file not found

I’m running Jenkins v2.263.2 with Terraform plugin on Debian 10.
I have created a freestyle project to trigger my terraform deployment, which is first pulling from my git repo and the trigger terraform, but at the terraform step I’m getting this error:

FATAL: java.io.FileNotFoundException: Configuration path not found [/var/lib/jenkins/workspace/Terraform/terraform/test.tf].
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setupWorkspace(TerraformBuildWrapper.java:367)
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeGet(TerraformBuildWrapper.java:208)
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:256)
	at hudson.model.Build$BuildExecution.doRun(Build.java:157)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
	at hudson.model.Run.execute(Run.java:1907)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)

Finished: FAILURE

Also if I look at the OS level I do have access to this file with jenkins user, so I’m not clear what is wrong with my setup.

jenkins@jenkins:~/workspace/Terraform/terraform$ cat test.tf
data "xenorchestra_template" "template" {
    name_label = "Galaxy_Template"
}

data "xenorchestra_network" "net" {
  name_label = "ETH"
}

resource "xenorchestra_vm" "bar" {
    memory_max = 1073733632
    cpus  = 1
    name_label = "MyName"
    name_description = "Mydescription"
    template = data.xenorchestra_template.template.id
    network {
          network_id = data.xenorchestra_network.net.id
    }

    disk {
      sr_id = "c7e5cf80-2b3e-c0ed-6f1e-09f1417b7d24"
      name_label = "WDisk"
      size = 62212254720
    }
}

The terraform run does not inherit the env variables (parameters) set by the job

Using a parameterized build, the terraform execution does not appear to "see" environment variables from parameters.

Example: Set parameter of TF_VAR_NAME with value of derp

This should set the value of var.NAME during the terraform run but it does not.

These parameters can be referenced in the Resource Variables section of the plugin with NAME = "$TF_VAR_NAME" in the Resource Variables section, but it's not as ideal.

Works fine and sets var.NAME properly when I launch terraform in Execute Script section of Build, but the plugin is a better option.

The auto-approval in TF is preventing builds from completing.

Jenkins - 2.89.4
Terraform Plugin - 1.0.9
Terraform => 0.11.0
centos - 7

Version 0.11.0 of terraform introduced an auto-approval flag and this is preventing my build from completing.

see the jenkins log output:

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value:

Apply cancelled.

FATAL: java.lang.Exception: Terraform Apply failed: 1
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeApply(TerraformBuildWrapper.java:249)
	at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:269)
	at hudson.model.Build$BuildExecution.doRun(Build.java:157)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1724)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)

Finished: FAILURE

rolling back to version 0.10.8 resolved my issue.

Support running "terraform get"

Current behavior: Running the plugin with a terraform configuration that uses modules errors out since terraform get has not been run. I don't see a way to add this command prior to the terraform apply that the plugin triggers.

Desired behavior: terraform get is always executed before terraform apply. It's an idempotent operation and reasonably fast, so running every time shouldn't be an issue.

Nullpointer exception when making a call to the plugin

Hi.

I have an AKS cluster with 3 Jenkins running, same version (2.263.4) in two of them, and the last version (2.303.3) for the other.

Same version of the plugin in the three of them (1.0.10).

Same plugin config in all Jenkins:
image

I also have the same pipeline in all of them.


pipeline {
    options {
        timestamps ()
    }
    agent {
        kubernetes {
            yaml '''
        apiVersion: v1
        kind: Pod
        spec:
          containers:
          - name: amazonlinux
            image: amazonlinux:latest
            command:
            - sleep
            args:
            - infinity
        '''
        defaultContainer 'amazonlinux'
        }
    }
    stages {
       stage('Terraform init and plan main Data infrastructure')
        {
            options {
                timeout(time: 1, unit: 'HOURS')
            }
            steps
            {
                script{
                        def terraform_home = tool "Terraform"
                }
            }
        }
    }
}

So in two of the Jenkins, one in version 2.263.4 and the other in version 2.303.3, the Pipeline works perfectly, but in the third one i get this:

java.lang.NullPointerException
	at org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:153)
	at org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:136)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

The log in the other Jenkins looks like this:

16:56:41  Unpacking https://releases.hashicorp.com/terraform/1.0.7/terraform_1.0.7_linux_amd64.zip to /home/jenkins/agent/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform on tests-testterraform-4-jlgk9-0261g-dcx1g
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
Finished: SUCCESS

I've checked every configuration in jenkins and they're all the same, the plugin config is all the same in the three of them.

Do you have any insight of what could be happening?

more a question

Hi working with plugin, but I seem to quite understand something:

Get works nicely the modules are "downloaded" into $WORKSPACE/terraform. But then it fails because it is looking for the config files $WORKSPACE/terraform-plugin although I set the Configuration Path to "terraform"

Does it run the script in the wrong dir?

[terraform] $
/var/lib/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform_0.6.16/terraform get -update
Get: file:///jenkinsdatadrive/jenkins/jobs/test-tf/workspace/terraform/rds (update)
....
Get: file:///jenkinsdatadrive/jenkins/jobs/test-tf/workspace/terraform/teradata (update)
[terraform-plugin] $ /var/lib/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform_0.6.16/terraform apply -input=false -state=/var/lib/jenkins/jobs/test-tf/workspace/terraform-plugin/terraform-plugin.tfstate -var-file=/var/lib/jenkins/jobs/test-tf/workspace/terraform-plugin/variables4987469359746446352.tfvars
�[31mError loading config: No Terraform configuration files found in directory: /jenkinsdatadrive/jenkins/jobs/test-tf/workspace/terraform-plugin�

try to run terraform from jenkins pipeline.

Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building in workspace C:\ProgramData\Jenkins.jenkins\workspace\only_poweshell
FSSCM.checkout D:\terraform_jenkins\jenkins_terra\ to C:\ProgramData\Jenkins.jenkins\workspace\only_poweshell
FSSCM.check completed in 104 milliseconds
[GitCheckoutListener] SCM 'hudson.plugins.filesystem_scm.FSSCM' is not of type GitSCM
[only_poweshell] $ "C:\Program Files\terraform\terraform.exe" get
[only_poweshell] $ "C:\Program Files\terraform\terraform.exe" apply -input=false -state=C:\ProgramData\Jenkins.jenkins\workspace\only_poweshell\terraform-plugin\terraform-plugin.tfstate
�[31mâ•·�[0m�[0m
�[31m│�[0m �[0m�[1m�[31mError: �[0m�[0m�[1merror configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
�[31m│�[0m �[0m
�[31m│�[0m �[0mPlease see https://registry.terraform.io/providers/hashicorp/aws
�[31m│�[0m �[0mfor more information about providing credentials.
�[31m│�[0m �[0m
�[31m│�[0m �[0mError: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request send failed, Get "http://169.254.169.254/latest/meta-data/iam/security-credentials/": dial tcp 169.254.169.254:80: i/o timeout
�[31m│�[0m �[0m�[0m
�[31m│�[0m �[0m
�[31m│�[0m �[0m�[0m with provider["registry.terraform.io/hashicorp/aws"],
�[31m│�[0m �[0m on providers.tf line 1, in provider "aws":
�[31m│�[0m �[0m 1: provider "aws" �[4m{�[0m�[0m
�[31m│�[0m �[0m
�[31m╵�[0m�[0m
FATAL: java.lang.Exception: Terraform Apply failed: 1
at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeApply(TerraformBuildWrapper.java:249)
at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:269)
at hudson.model.Build$BuildExecution.doRun(Build.java:158)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522)
at hudson.model.Run.execute(Run.java:1896)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)

Finished: FAILURE

Support for init for versions > 0.10.0

As of v0.10, provider plugins are no longer included in the main Terraform distribution. Instead, they are distributed separately and installed automatically by the terraform init command.

https://www.terraform.io/upgrade-guides/0-10.html

Without an option to run init, an error will be returned:

Could not satisfy plugin requirements.

Plugins are external binaries that Terraform uses to access and manipulate
resources. The configuration provided requires plugins which can't be located,
don't satisfy the version constraints, or are otherwise incompatible.

Jenkins Pipeline 'tool' step not returning 'home'

I am having an issue with the Jenkins Pipeline tool step being able to return the homedir of where terraform is installed. In examples, I see:

def mvnHome = tool 'M3'
sh "${mvnHome}/bin/mvn -B verify"

When I try this with my installed maven plugin, it returns mvnHome correctly. However, when I try this with my terraform install (automatic install from bintray) I am seeing nothing returned as the tfHome for something like:

def tfHome = tool 'Terraform'

Furthermore, I see that in the XML for the plugin:

    <org.jenkinsci.plugins.terraform.TerraformInstallation>
      <name>Terraform</name>
      <home></home> <-------NOTICE 
      <properties>
        <hudson.tools.InstallSourceProperty>
          <installers>
            <org.jenkinsci.plugins.terraform.TerraformInstaller>
              <id>0.7.1-linux-amd64</id>
            </org.jenkinsci.plugins.terraform.TerraformInstaller>
          </installers>
        </hudson.tools.InstallSourceProperty>
      </properties>
    </org.jenkinsci.plugins.terraform.TerraformInstallation>

I think the getHome() is not returning anything but I am not 100% sure. Any ideas on this?

Not compatible with `wrap` pipeline step?

These docs attempt to describe that plugins normally found in the Build Environment section of a freestyle project can be used in a pipeline:
https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#wrap-general-build-wrapper

I am not sure what dropdown they are talking about. I assume that this plugin is not compatible with pipelines, therefore this is a non-bug, but wanted to submit a feature request if possible for pipelines to be supported by TerraformBuildWrapper in the wrap step like so:

wrap([$class: 'TerraformBuildWrapper']) {
  ...
}

Currently I get:

java.lang.UnsupportedOperationException: no known implementation of class jenkins.tasks.SimpleBuildWrapper is named TerraformBuildWrapper
...
Caused: java.lang.IllegalArgumentException: Could not instantiate {delegate={$class=TerraformBuildWrapper}} for org.jenkinsci.plugins.workflow.steps.CoreWrapperStep

Tiny, unreadable screenshots in README.md

Hi all,

The screenshots in README.md are very small images. They are basically unreadable.

I have tried to fix this locally and raise a PR, however since I am not able to read the current images, I cannot capture my own and add them to the repo 😪

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.