-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Dev #21
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
base: main
Are you sure you want to change the base?
Dev #21
Changes from 6 commits
6233152
20bc619
b721375
eced5f2
9b48127
b4cec78
923a06f
d0c419f
ef9e5b9
016cd5e
e3fb6f8
014e4ac
2daa5e1
da631d3
0bebcb3
7b71481
9c73715
3f31783
7963f1c
5f72585
39dee0c
c12cad9
34bee1f
37c3b47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||
| pipeline { | ||||||||||
| agent any | ||||||||||
|
|
||||||||||
| parameters { | ||||||||||
| choice(name: 'ACTION', choices: ['apply', 'destroy'], description: 'Choose whether to apply or destroy the Terraform EKS module') | ||||||||||
| } | ||||||||||
|
|
||||||||||
| environment { | ||||||||||
| TF_DIR = 'eks-install' | ||||||||||
| AWS_CREDENTIALS_ID = 'your-aws-credentials-id' | ||||||||||
| AWS_DEFAULT_REGION = 'ap-south-1' | ||||||||||
| } | ||||||||||
|
|
||||||||||
| stages { | ||||||||||
| stage('Checkout Code') { | ||||||||||
| steps { | ||||||||||
| checkout scm | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| stage('Terraform Init') { | ||||||||||
| steps { | ||||||||||
| dir("${env.TF_DIR}") { | ||||||||||
| withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "${AWS_CREDENTIALS_ID}", accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) { | ||||||||||
| sh 'terraform init' | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| stage('Terraform Plan') { | ||||||||||
| steps { | ||||||||||
| dir("${env.TF_DIR}") { | ||||||||||
| withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "${AWS_CREDENTIALS_ID}", accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) { | ||||||||||
| sh "terraform plan ${params.ACTION == 'destroy' ? '-destroy' : ''} -out=tfplan" | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| stage('Manual Approval') { | ||||||||||
| steps { | ||||||||||
| input message: "Review plan for folder '${env.TF_DIR}'. Proceed with ${params.ACTION}?", ok: 'Proceed' | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| stage('Terraform Execute') { | ||||||||||
| steps { | ||||||||||
| dir("${env.TF_DIR}") { | ||||||||||
| withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "${AWS_CREDENTIALS_ID}", accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) { | ||||||||||
| script { | ||||||||||
| if (params.ACTION == 'apply') { | ||||||||||
| sh 'terraform apply -auto-approve tfplan' | ||||||||||
| } else if (params.ACTION == 'destroy') { | ||||||||||
| sh 'terraform apply -destroy -auto-approve' | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
sed -n '31,57p' JenkinsfileRepository: iam-veeramalla/ultimate-devops-project-aws Length of output: 1558 🌐 Web query:
💡 Result: To apply a saved Terraform plan file, you provide the path to the plan file as an argument to the terraform apply command [1][2]. Usage: terraform apply [plan file] Key details of this workflow: - Creation: You first generate the plan file using the -out option with the terraform plan command (e.g., terraform plan -out=tfplan) [3][4]. - Execution: When you pass a saved plan file to terraform apply, Terraform executes the exact operations recorded in that file [1][4]. - No Confirmation Required: Terraform interprets the use of a saved plan file as explicit approval; therefore, it does not prompt for confirmation or require the -auto-approve flag [1][2][4]. - Restriction on Options: When using a saved plan file, you cannot specify additional planning options or modes (such as -var, -replace, -destroy, or -refresh-only) [1][4]. The plan file already contains the finalized set of actions, and these options only apply when Terraform is generating a new plan [1]. - Automation: This two-step workflow (plan then apply) is recommended for automation and CI/CD pipelines to ensure that the infrastructure changes applied are exactly those that were previously reviewed [3][2][5]. It is recommended to use the terraform show command to inspect the contents of a saved plan file before applying it [1][6]. Additionally, be aware that saved plan files may contain sensitive information in cleartext if your configuration or variables include sensitive data [3][5]. Citations:
🌐 Web query:
💡 Result: When you pass a saved plan file to the terraform apply command, Terraform does not allow you to specify additional planning modes or options [1][2]. The plan file already contains the final results of all planning decisions, including the intended operations, and cannot be modified at the execution stage [1]. Specifically, this means you cannot use options like -destroy, -refresh-only, or -replace when applying a saved plan [1][2]. If you wish to apply a destroy plan, you must specify the -destroy option when creating the plan with terraform plan, save that plan to a file using the -out option, and then pass that saved file to terraform apply [3][2]. In summary, the design of the saved plan workflow is that the plan file encapsulates the entire execution strategy [1]. Any customization of that strategy, including changing the mode of operation (such as destroy mode) or applying resource replacements, must occur during the planning phase, not the application phase [1][4]. Providing additional planning-related flags alongside a saved plan file will cause Terraform to reject the command [1]. Citations:
🌐 Web query:
💡 Result: When you use a saved plan file with the terraform apply command, Terraform automatically skips the interactive confirmation prompt [1][2][3]. Terraform interprets the act of providing a saved plan file as your approval of the planned operations, so it proceeds to execute the changes immediately [1]. Because this behavior is automatic for saved plans, you do not need—and cannot use—the -auto-approve flag in this context [1]. Terraform will ignore the -auto-approve flag if it is provided alongside a plan file [1]. This workflow is specifically designed for automation, ensuring that the exact changes you reviewed during the plan phase are the ones performed during the apply phase [1][2][3]. To use this workflow: 1. Create a saved plan file: terraform plan -out=tfplan 2. Apply that specific plan file: terraform apply "tfplan" [3] Citations:
Apply the approved destroy plan instead of generating a new one.
Proposed fix- } else if (params.ACTION == 'destroy') {
- sh 'terraform apply -destroy -auto-approve'
+ } else if (params.ACTION == 'destroy') {
+ sh 'terraform apply tfplan'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| post { | ||||||||||
| always { | ||||||||||
| cleanWs() // Cleans up workspace after execution | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.