Skip to content

This repository helps to build infrastructure such as AWS using Terraform with Jenkins Pipeline.

Notifications You must be signed in to change notification settings

Omidznlp/Terraform-Jenkins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Terraform-Jenkins

This repository helps to build infrastructure such as AWS using Terraform with Jenkins Pipeline.

Jenkins and Terraform and AWS

Screen Shot 2021-07-01 at 4 43 17 PM

Jenkins

Install Terraform plugin

To Install Terraform plugin,

Go to Manage Jenkins > Manage Plugins >Available > search Terraform > Choose to install Terraform plugin.

Add AWS Credentiols

To configure AWS credentials in Jenkins:

  1. Install Pipeline: AWS Steps navigate to Manage Jenkins > Manage Plugins under the Available tab of the Jenkins dashboard. Choose to install the Pipeline: AWS Steps plugin without a restart.

  2. Add Aws credentials: You can add credentials by navigating to Manage Jenkins > Manage Credentials > Jenkins (global) > Global Credentials > Add Credentials. Choose kind as AWS credentials and enter "terraform-credentials" as the ID. Enter the access key ID and access key secret, then select OK. 1cred Note! if you can not see the AWS credentials after adding the plugin. please go to Manage Jenkins > Configure Credential Providers > change Providers to all available and change types to all availlable. 2 credentioalproviders

Add Terraform Pipeline

To add Terraform Pipeline, Go to new item > Enter an item name > choose Pipline > Click OK. Then, To add Jenkinsfile: Go to Advanced Project Options > In Pipline Section > Select "Pipline script from SCM" . > Select "Git" in SCM section > Insert Repository URL (https://github.com/Omidznlp/Terraform-Jenkins.git) in Repositoriis Section

ec2modual

In Section Branches to build, Insert (*/master) > In Script Path, Insert (Jenkinsfile) > Click Save.

ec22

Jenkins Nodes Label

I used agent with "master" label to build Terraform Pipile, In Jenkinsfile into repositoy you can find it.

    agent {
      node {
        label "master"
      } 
`    }

I gave my Jenkins server the label "master," and then I ran Terraform on it. Go to Manage Jenkins > Click "Manage nodes and clouds" > Select setting (left side of the list of nodes) > Under the label section, add "master" > Save it.

nodelabel

Note! Simply, you can change the label on the Jenkinsfile or choose your node from your node lists from which you would like to execute terraform and then add the "master" label to it.

Run Jenkins Pipline

Build with parameters: choose an action "apply or destroy"? choose param

Before "TF Apply" or TF Destroy" stage, you must approve it manually in the Approval and Removal Stage by clicking on it and selecting "Proceed.".

pipiline1

About

This repository helps to build infrastructure such as AWS using Terraform with Jenkins Pipeline.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages