วันนี้เรายินดีประกาศความพร้อมของ HashiCorp Terraform Redis Enterprise Cloud provider ในขณะที่ทีมพัฒนายอมรับหลักการ DevOps มากขึ้น เช่น continuous integration/continuous delivery (CI/CD) ความจำเป็นในการจัดการโครงสร้างพื้นฐานเป็นโค้ด (infrastructure as code) กลายเป็นความสามองที่เกือบจำเป็นสำหรับบริการ cloud ใดๆ เครื่องมือชั้นนำในพื้นที่ infrastructure as code คือ HashiCorp Terraform รองรับผู้ให้บริการ cloud และบริการหลักด้วย providers และ modules ระบบนิเวศ automation โครงสร้างพื้นฐาน cloud สำหรับการจัดเตรียม (provisioning), compliance และการจัดการ cloud, infrastructure และ service ใดๆ
Terraform คืออะไร?
หากคุณไม่คุ้นเคย Terraform เป็นเครื่องมือสำหรับสร้าง เปลี่ยนแปลง และจัดการเวอร์ชันโครงสร้างพื้นฐานอย่างปลอดภัยและมีประสิทธิภาพ จัดการทุกอย่างด้วยโค้ด ไฟล์การกำหนดค่า (configuration files) ใช้สำหรับอธิบายคอมโพเนนต์ที่จำเป็นสำหรับการรันแอปพลิเคชันของคุณ Terraform จัดการองค์ประกอบโครงสร้างพื้นฐานเกือบทุกอย่าง รวมถึง bare metal, virtual machines, cloud instances และบริการ Infrastructure-as-a-Services (IaaS) ยอดนิยมอื่นๆ มากมาย คอมโพเนนต์ใน application stack ของคุณถูกแทนเป็น resources ใน Terraform Terraform provider มีหน้าที่เข้าใจ API interactions ของ resource ที่เกี่ยวข้อง และเผยแพร่คุณลักษณะของ resource ออกสู่โลกภายนอก
วันนี้เราประกาศอะไร?
เพื่อตอบสนองความต้องการที่เพิ่มขึ้นนี้ Redis ได้พัฒนา Terraform provider สำหรับ Redis Enterprise Cloud HashiCorp Terraform Redis Enterprise Cloud Provider ช่วยให้ลูกค้าจัดเตรียมและจัดการ Redis Enterprise Cloud subscriptions, databases และ network peering ได้อย่างง่ายดายเป็นโค้ด บนผู้ให้บริการ cloud ใดก็ได้
เริ่มต้นอย่างรวดเร็ว (Quick start)
เพื่อสาธิตว่า Redis Enterprise Cloud's Terraform Provider ทำงานอย่างไร และทำอะไรได้ เราจะสร้าง subscription ตัวอย่างพร้อมฐานข้อมูล 2 ตัว โดยหนึ่งในนั้นใช้โมดูล RedisJSON
ข้อกำหนดเบื้องต้น (Prerequisites):
- ติดตั้ง Terraform ในเครื่อง local แล้ว
- มีบัญชี Redis Enterprise Cloud
- เปิดใช้งาน programmatic access สำหรับบัญชี Redis Enterprise Cloud
เริ่มต้นด้วยการเก็บ Redis Enterprise Cloud API keys เป็น environment variables:
$ export REDISCLOUD_ACCESS_KEY=<your API access key>
$ export REDISCLOUD_SECRET_KEY=<your API secret key>
สร้างโฟลเดอร์ใหม่และวางไฟล์ Terraform HCL ที่แสดงด้านล่าง ให้ชื่อไฟล์ว่า rediscloud-tf-example.tf:
terraform { required_providers { rediscloud = { source = "Redis/rediscloud" version = "0.2.0" } } } # Provide your credit card details data "rediscloud_payment_method" "card" { card_type = "Visa" last_four_numbers = "1234" } # Generates a random password for the database resource "random_password" "passwords" { count = 2 length = 20 upper = true lower = true number = true special = false } resource "rediscloud_subscription" "example" { name = "Demo" payment_method_id = data.rediscloud_payment_method.card.id memory_storage = "ram" cloud_provider { #Running in AWS on Redis resources provider = "AWS" cloud_account_id = 1 region { region = "eu-west-1" networking_deployment_cidr = "10.0.0.0/24" preferred_availability_zones = ["eu-west-1a"] } } database { name = "redis-db" protocol = "redis" memory_limit_in_gb = 1 replication = true data_persistence = "none" throughput_measurement_by = "number-of-shards" throughput_measurement_value = 2 password = random_password.passwords[0].result } database { name = "db-json" protocol = "redis" memory_limit_in_gb = 1 replication = true data_persistence = "aof-every-1-second" module { name = "RedisJSON" } throughput_measurement_by = "operations-per-second" throughput_measurement_value = 10000 password = random_password.passwords[1].result } }
ขั้นตอนต่อไปคือการ initialize terraform environment โดยรันคำสั่งนี้:
$ terraform init
ผลลัพธ์ควรจะเป็นแบบนี้:
... Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. ...
หลังจาก Terraform initialize สำเร็จแล้ว ให้รันคำสั่งต่อไปนี้เพื่อให้ Terraform สร้างแผน (plan):
$ terraform plan
เอาต์พุทควรจะคล้ายกับนี้:
... Plan: 1 to add, 0 to change, 0 to destroy. ...
ตอนนี้ ให้ Terraform ทำงานและจัดเตรียมฐานข้อมูลของเรา:
$ terraform apply
คำสั่ง terraform apply อาจใช้เวลาหลายนาที เมื่อเสร็จสิ้น ควรจะได้ผลลัพธ์แบบนี้:
… rediscloud_subscription.example: Creation complete after 8m16s [id=103873] Apply complete! Resources: 1 added, 0 changed, 0 destroyed. ...
เห็นได้ว่าเราจัดเตรียมฐานข้อมูลใหม่ 2 ตัวแล้ว สิ่งที่ต้องทำคือ copy database endpoints ไปใช้กับแอปพลิเคชัน คุณยังสามารถใช้ RedisInsight, GUI สำหรับการพัฒนาแอป Redis ที่ราบรื่น เพื่อเชื่อมต่อและสำรวจข้อมูลได้
คอนโซล Redis Enterprise Cloud แสดง subscription และ database ใหม่:
เมื่อคุณเล่นเสร็จแล้ว สามารถลบทุกอย่างได้โดยรันคำสั่งนี้:
$ terraform destroy
ต่อไปจะเป็นอย่างไร?
เราจะยังคงขยายความสามารถของ HashiCorp Terraform Redis Enterprise Cloud Provider หากคุณมีไอเดียหรือคุณลักษณะที่ต้องการให้เรารองรับใน provider หรือพบบั๊ก กรุณาแจ้งเราโดยเปิด issue ใน GitHub repository ของเรา หรือส่งอีเมลมาที่ pm.group@redis.com
สำหรับ use cases แบบ production เราขอแนะนำให้ใช้ Terraform Cloud ซึ่งเป็นบริการ cloud-based ของ HashiCorp สำหรับ Terraform จะช่วยให้คุณเก็บ credentials ในสภาพแวดล้อมที่ปลอดภัยนอกไฟล์ config และ source control Terraform Cloud ยังมีคุณลักษณะทำงานร่วมกัน เช่น free remote state storage, custom workspace permissions, version-control system integration, และ policy as code คุณสามารถสมัครฟรีได้ที่ terraform.io/cloud