This repository helps to build infrastructure such as AWS using Terraform with Jenkins Pipeline.
To Install Terraform plugin,
Go to Manage Jenkins > Manage Plugins >Available > search Terraform > Choose to install Terraform plugin.
To configure AWS credentials in Jenkins:
-
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.
-
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.
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.
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
In Section Branches to build, Insert (*/master) > In Script Path, Insert (Jenkinsfile) > Click Save.
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.
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.
Build with parameters: choose an action "apply or destroy"?
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.".