Hôm nay chúng tôi vui mừng thông báo HashiCorp Terraform Redis Enterprise Cloud provider đã có sẵn. Khi development team ngày càng áp dụng DevOps principles như continuous integration/continuous delivery (CI/CD), nhu cầu quản lý infrastructure as code trở thành capability gần như bắt buộc cho bất kỳ cloud service nào. Công cụ hàng đầu trong không gian infrastructure as code là HashiCorp Terraform, hỗ trợ major cloud providers và services với providers và modules trong ecosystem tự động hóa cơ sở hạ tầng cloud cho provisioning, compliance, và quản lý bất kỳ cloud, infrastructure, và service nào.
Terraform là gì?
Nếu bạn chưa quen, Terraform là công cụ xây dựng, thay đổi, và versioning infrastructure an toàn và hiệu quả, quản lý mọi thứ bằng code. Configuration files mô tả các component cần chạy ứng dụng. Terraform quản lý hầu như mọi thành phần infrastructure, bao gồm bare metal, virtual machines, cloud instances, và nhiều dịch vụ Infrastructure-as-a-Services (IaaS) phổ biến. Các component trong application stack được biểu diễn như resources trong Terraform. Terraform provider chịu trách nhiệm hiểu API interactions của resource liên quan và expose features của resource ra bên ngoài.
Chúng tôi thông báo gì hôm nay?
Để đáp ứng nhu cầu tăng, Redis đã phát triển Terraform provider cho Redis Enterprise Cloud. HashiCorp Terraform Redis Enterprise Cloud Provider cho phép khách hàng triển khai và quản lý Redis Enterprise Cloud subscriptions, databases, và network peering dễ dàng as code, trên bất kỳ cloud provider nào.
Quick start
Để demo cách Redis Enterprise Cloud's Terraform Provider hoạt động và làm gì, hãy tạo sample subscription với 2 database, một dùng module RedisJSON.
Điều kiện tiên quyết:
- Terraform cài local.
- Tài khoản Redis Enterprise Cloud.
- Programmatic access enabled cho tài khoản Redis Enterprise Cloud.
Bắt đầu bằng cách lưu Redis Enterprise Cloud API keys làm environment variables:
$ export REDISCLOUD_ACCESS_KEY=<your API access key>
$ export REDISCLOUD_SECRET_KEY=<your API secret key>
Tạo folder mới và đặt Terraform HCL file như sau. Gọi file 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 } }
Bước tiếp theo: khởi tạo terraform environment bằng lệnh:
$ terraform init
Kết quả như sau:
... 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. ...
Sau khi Terraform initialized thành công, chạy lệnh sau để Terraform tạo plan:
$ terraform plan
Output tương tự:
... Plan: 1 to add, 0 to change, 0 to destroy. ...
Bây giờ để Terraform làm phép và provision databases:
$ terraform apply
Lệnh terraform apply có thể mất vài phút, khi xong sẽ cho kết quả:
… rediscloud_subscription.example: Creation complete after 8m16s [id=103873] Apply complete! Resources: 1 added, 0 changed, 0 destroyed. ...
Như bạn thấy, chúng ta đã provision 2 database mới. Chỉ cần lấy endpoint database và plug vào ứng dụng. Bạn cũng có thể dùng RedisInsight, GUI cho phát triển ứng dụng Redis streamlined, để kết nối và explore dữ liệu.
Redis Enterprise Cloud console hiển thị subscription và database mới:
Khi xong, bạn có thể tear down mọi thứ bằng lệnh:
$ terraform destroy
Tiếp theo là gì?
Chúng tôi sẽ tiếp tục mở rộng khả năng HashiCorp Terraform Redis Enterprise Cloud Provider. Nếu bạn có ý tưởng hoặc feature muốn hỗ trợ trong provider hoặc tìm bug, hãy báo cho chúng tôi bằng cách open issue trong GitHub repository. Bạn cũng có thể liên hệ pm.group@redis.com.
Cho production use cases, chúng tôi khuyên dùng Terraform Cloud, giải pháp cloud-based của HashiCorp cho Terraform. Điều này cho phép lưu credentials trong secure environment ngoài configuration file và source control. Terraform Cloud cũng có collaborative features như free remote state storage, custom workspace permissions, version-control system integration, cũng như policy as code. Đăng ký miễn phí tại terraform.io/cloud.