I need to launch few instance on AWS using terraform script, i am automating the whole process using jenkins
pipeline{
agent any
tools {
terraform 'terraform'
}
stages{
stage('Git Checkout'){
steps{
git branch: 'main', credentialsId: 'gitlab id', url: 'https://gitlab.com/ndey1/kafka-infra'
}
}
stage('Terraform init'){
steps{
sh 'cd terraform-aws-ec2-with-vpc'
sh 'terraform init'
}
}
stage('Terraform plan'){
steps{
sh 'terraform plan'
}
}
stage('Terraform apply'){
steps{
sh 'terraform apply --auto-approve'
}
}
}
}
but while running jenins jobs ( pipeline ) it throws the error
+ cd terraform-aws-ec2-with-vpc
[Pipeline] sh
+ terraform init
[0m[1mTerraform initialized in an empty directory![0m
The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.[0m
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Terraform plan)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ terraform plan
[31m?[0m[0m
[31m│[0m [0m[1m[31mError: [0m[0m[1mNo configuration files[0m
[31m│[0m [0m
[31m│[0m [0m[0mPlan requires configuration to be present. Planning without a configuration
[31m│[0m [0mwould mark everything for destruction, which is normally not what is
[31m│[0m [0mdesired. If you would like to destroy everything, run plan with the
[31m│[0m [0m-destroy option. Otherwise, create a Terraform configuration file (.tf
[31m│[0m [0mfile) and try again.
[31m?[0m[0m
though all terraform cod is in the same dir named "kafka-infra" but still its saying no configuration file in dir but terraform init runs successfully , the error comes in the stage of " terraform plan"
See Question&Answers more detail:os