Learn How to Create Terraform Custom Modules for Azure |
Вставка
- Опубліковано 7 лип 2024
- In this Episode, I’ll show you how to create your first Terraform Module to use in Azure! We will walk-through, the standard terraform code and how to generalise it into a module. I’ll run through a demo to show you how to write code.
Episode Timecodes:
0:00 Intro
0:38 Terraform Modules
1:00 Why use Modules?
2:37 Standard Structure - Terraform Configuration Files
3:14 Module Structure - Terraform Configuration Files
3:46 Terraform Base Code Breakdown
4:39 Turn your Code into a Module
5:03 Module Code Breakdown
7:22 Demonstration - Deployment Code
8:00 Creating the Module Code
11:57 Module Standards
14:32 Calling the Child Module
16:16 Lets Apply!
17:40 Module Nesting - Closing Notes
18:14 Create Modules for Everything? Closing Notes
Episode Code: github.com/someoneelsescloud/...
Hashicorp Learn - Reuse Configuration with Modules
learn.hashicorp.com/collectio...
Hashicorp - Modules Overview
www.terraform.io/docs/languag...
Hashicorp - Module Structure
www.terraform.io/docs/languag...
Hashicorp - Creating Modules
www.terraform.io/docs/languag...
Terraform Module Registry
registry.terraform.io/browse/...
Show your appreciation and support the channel: www.buymeacoffee.com/some1els...
Download Someone Else's Cloud Wallpapers! Add some vibrant colours and positive energy to your Work from Home environment to keep you amped! ✌️ www.someoneelsescloud.com/epi...
Instagram: / someoneelsescloud
Twitter: / some1elsescloud
Github: github.com/someoneelsescloud
Sign up for the Newsletter: eepurl.com/hEYUdP
See all links to all platforms here: www.someoneelsescloud.com/links
#azure #terraform #iac #modules - Наука та технологія
exactly what I needed, a clear explanation! thanks
Glad it helped!
Needed this! Great work and great content.
Thanks mate! Hope it helps 🤗
@@SomeoneElsesCloud it definitely does. It would be great if you can carry on with this and use Terratest or something for integration/unit testing.
@@AdilKhan_ thanks, sounds like a plan!
exactly what i needed... learned a lot.. subscribed! thanks!
Awesome, thank you!
Clear explanation.
Thank You
Glad it was helpful! ✌️
exactly what I needed! Thanks a lot!
Glad it helped!
Thanks for sharing
No problems, hope it helped! ✌️
Do you use source module git clone in production?
How are variables dynamic changed if developers want to change
Hey there, this is an interesting question, but I'll try and keep it short. Depends on how your modules are structured, you could store them in a folder in your github repo with your terraform code or you could store them in github ideally per repository and use release tags to version control them. There's no right way to do this and it comes down to what works for your environment. If developers want to create their own variables, they could test the module locally or if it's in github they could just work from their own branch, but if it's changes for everyone using the module, it should be managed through versions or at least pull requests. Not really sure if this answers your question, but there definately multiple ways to approach modules! 😊
Great work Sonny!
I hope somebody can help me to solve this issue and understand how to implement the best approach. I have a number of situations where I need to retry a task n-times if it fails.
My ask is, I need help writing a Terraform module to monitor an azure task which is to restart it in case it encounters an exception. retry logic). If an exception is thrown, the task should be retried up to the max-retry count.
Hey O'sean, to best honest I have not done anything like that, but it sounds like you need a scheduler and scripts. Terraform is not really a monitoring tool, because you would need it to constantly apply, thus sounds like you need a scheduler and script like runbooks or azure devops using a the cron scheduler.
I've only really seen where null_resource is used to execute a script but eventually that becomes redundant as there is no state of this resouce, so it will just execute everytime with no real feedback.. So its really a bandaid untul Terraform supports the issue correctly. Not sure if this helps but if you have an issue running an Azure task, Terraform might not be the right way?
@@SomeoneElsesCloud thank you so much for your response! Do you by any chance have plans to do anything like this in the future (using scheduler of course)
I've mainly used it to execute PowerShell scripts. What do you need to do? Maybe a summarised version? I liked to solve problems 😬
@UCrMpQutaRnhQV0mq7fEag0Q I want to retry a failed operation n-times, I have done my research and I found Terragrunt as a better alternative to achieve this.
Let's say I try to create or delete a resource I want to be able to retry that operation using auto-retry/retry the operation a number of times if it fails on first try
Interesting, I just read this auto-retry feature on terragrunt. We use Terraform Enterprise and we can re-queue old runs from the portal ui but I have only needed to do this when I'm trying to uplift modules and have to modify state or encounter a sequencing issue that needs some kind of depends_on.
Hi Sunny, Can we use modules with Azure devops?
Hey Srujan, sorry for the late reply! Yes modules are just code. Azure DevOps will just execute the code just like you do locally. If it's just a local module (stored in GitHub with your code) it should just work. It's it's a remote module (stored in a remote repository) then you would need to ensure connection and authentication is setup correctly.
@@SomeoneElsesCloud thanks sunny for your reply !
I have another question can we use parameters in azure pipelines with terraform while running the pipeline can we put our required values of over writing the var file or tfvars file ?
Hey Srujan, you would rather use variable groups or variables and inject then as variables with your command line options with Terraform, see this video, which will give you some ideas. ua-cam.com/video/ea4NjxjuM8U/v-deo.html You could also add variables via the GUI too but it would be better to define them in code.
do you have github repo for this?
Hey yep its in the comments, but this is whre its at github.com/someoneelsescloud/ep14_create_azure_terraform_module