DEV Community

Vatthanachai Wongprasert
Vatthanachai Wongprasert

Posted on

1

Hello Terraform, Part 1: เตรียมเครื่องมือกันก่อน

พึ่งได้มีโอกาสแตะ Terrafrom ก็เลยอยากจะมาเขียนบันทึกเอาไว้อ่านทีหลังครับ แต่.. ก็คิดว่าอาจจะพอมีประโยชน์สำหรับผู้ที่สนใจ แต่ก็ไม่รู้ว่าจะเริ่มศึกษายังไงดีเลยเอาเป็นว่ามาแชร์ดีกว่า มาเริ่มกันเลยดีกว่า

ก่อนอื่นในบทความนี้จะใช้งาน Terraform ร่วมกับ Azure นะครับ ซึ่งถ้าจะใช้งานร่วมกับ cloud ตัวอื่นก็อาจจะต้องตรวจสอบข้อมูลของ Cloud ที่จะใช้งานก่อนนะครับ และในบทความนี้จะเป็นการเตรียมความพร้อมของเครื่องก่อนจะใช้งาน Terraform ครับ

เริ่มแรกก็ต้องไปสมัครใช้งาน Azure ก่อน โดยสามารถใช้งานแบบ Free Account หรือจะแบบเสียเงินก็ได้ครับ และสำหรับ Free Account ก็จะได้ $200 จะสามารถใช้งานได้ 30 วัน ส่วน service อื่นๆ สามารถใช้งานได้ 1 ปีครับ สำหรับวิธีการสมัครสามารถหาได้ใน Google ครับ

ขั้นตอนต่อไปก็จะติดตั้ง Terraform โดยใช้ Chocolatey เป็นตัวช่วยครับ โดยเราจะใช้ powershell ในการติดตั้ง โดยจะต้องเปิด powershell ด้วย Administrator และใช้คำสั่ง

c:\> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

สำหรับคำสั่งนี้สามารถดูได้จากหน้าเว็บนี้ ในกรณีที่อาจจะมีเปลี่ยนแปลงครับ
https://chocolatey.org/install

Alt Text

จากนั้นใช้คำสั่งนี้ เพื่ออัพเดท env ของ powershell หรือปิด powershell แล้วเปิดใหม่ด้วย Administrator ก็ได้

c:\> refreshenv

หลังจากนั้นก็จะเป็นการติดตั้ง Terraform โดยใช้คำสั่ง

c:\> choco install terraform -y

หากเครื่องใครติดตั้งแล้วก็อาจจะมีข้อความเหมือนเครื่องผมครับ
Alt Text

ลองใช้คำสั่งนี้เพื่อตรวจสอบ version ของ Terraform

c:\> terraform --version

Alt Text

ลำดับต่อไปก็ IDE ซึ่งเราจะใช้ VS Code ในการเขียนคำสั่ง (สำหรับการติดตั้งขอข้ามนะครับ) และเราจะทำการติดตั้ง extension ชื่อ Terraform ตามลิงค์นี้ https://marketplace.visualstudio.com/items?itemName=mauve.terraform

เท่านี้ก็พร้อมที่จะใช้งาน Terraform เพื่อสร้างระบบบน Azure แล้วครับ

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay