Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Bitbucket pipeline condition

Hi All,

I'm creating ElasticBeanStalk using bitbucket pipeline and terraform.

I have 3 environment, and each environment has 3 regions under the same account. 

I have also incorporated the IAM role and permission within the same pipeline. When trying to run pipeline for different region, it failed in IAM role & permission creation with an error resource already exists.

I want to use the pipeline variable to check if the IAM role/permission needs to create? If the value is True then it should run the script. 

 

I studied the bitbucket if condition, but it won't execute the terraform script, 

 

if $CREATE_ROLE; then
echo true
- cd createIamAcess
- terraform init -backend-config="bucket=$s3_Backend_Bucket_Name" -backend-config="key=$s3_Backend_StateFile_Location" -reconfigure
- terraform plan
- terraform apply -input=false -auto-approve
fi

 

Can anyone please advise, how to use the terraform script within the if condition? or any other alternate option. 

 

Regards,

Nikhil Shah

1 answer

0 votes
Erez Maadani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 01, 2023

Hey @Nikhil 

You can try using bash's implicit if:

[[ ! -z "$CREATE_ROLE" ]] && terraform init -backend-config="bucket=$s3_Backend_Bucket_Name" -backend-config="key=$s3_Backend_StateFile_Location" -reconfigure

Hope that helps

Hi,

Thank you for the suggesstion, it really helps. I have modified the script as follows: 

- cd createIamAcess
- if [[ "$CREATE_ROLE" == true ]]; then terraform init -backend-config="bucket=$s3_Backend_Bucket_Name" -backend-config="key=terraform.tfstate" -reconfigure && terraform apply -input=false -auto-approve; fi
# - |
here, CREATE_ROLE is pipeline ariable needs to set prior executing the pipeline 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events