Version: v1.0

Terraform

In this documentation, we will use Alibaba Cloud’s RDS (Relational Database Service), and Alibaba Cloud’s OSS (Object Storage System) as examples to show how to enable cloud services as part of the application deployment.

These cloud services are provided by Terraform.

Prepare Terraform Controller

Download the latest chart, like terraform-controller-chart-0.1.4.tgz, from the latest releases list and install it.

  1. $ helm install terraform-controller terraform-controller-0.1.2.tgz
  2. NAME: terraform-controller
  3. LAST DEPLOYED: Mon Apr 26 15:55:35 2021
  4. NAMESPACE: default
  5. STATUS: deployed
  6. REVISION: 1
  7. TEST SUITE: None

Apply Provider Credentials

By applying Terraform Provider credentials, Terraform controller can be authenticated to deploy and manage cloud resources.

Please refer to Terraform controller getting started on how to apply Provider for Alibaba Cloud or AWS.

Register alibaba-rds Component

Register alibaba-rds to KubeVela.

  1. apiVersion: core.oam.dev/v1alpha2
  2. kind: ComponentDefinition
  3. metadata:
  4. name: alibaba-rds
  5. annotations:
  6. definition.oam.dev/description: Terraform configuration for Alibaba Cloud RDS object
  7. type: terraform
  8. spec:
  9. workload:
  10. definition:
  11. apiVersion: terraform.core.oam.dev/v1beta1
  12. kind: Configuration
  13. schematic:
  14. terraform:
  15. configuration: |
  16. module "rds" {
  17. source = "terraform-alicloud-modules/rds/alicloud"
  18. engine = "MySQL"
  19. engine_version = "8.0"
  20. instance_type = "rds.mysql.c1.large"
  21. instance_storage = "20"
  22. instance_name = var.instance_name
  23. account_name = var.account_name
  24. password = var.password
  25. }
  26. output "DB_NAME" {
  27. value = module.rds.this_db_instance_name
  28. }
  29. output "DB_USER" {
  30. value = module.rds.this_db_database_account
  31. }
  32. output "DB_PORT" {
  33. value = module.rds.this_db_instance_port
  34. }
  35. output "DB_HOST" {
  36. value = module.rds.this_db_instance_connection_string
  37. }
  38. output "DB_PASSWORD" {
  39. value = module.rds.this_db_instance_port
  40. }
  41. variable "instance_name" {
  42. description = "RDS instance name"
  43. type = string
  44. default = "poc"
  45. }
  46. variable "account_name" {
  47. description = "RDS instance user account name"
  48. type = "string"
  49. default = "oam"
  50. }
  51. variable "password" {
  52. description = "RDS instance account password"
  53. type = "string"
  54. default = "Xyfff83jfewGGfaked"
  55. }

Register alibaba-oss Component

Register alibaba-oss to KubeVela.

  1. apiVersion: core.oam.dev/v1alpha2
  2. kind: ComponentDefinition
  3. metadata:
  4. name: alibaba-oss
  5. annotations:
  6. definition.oam.dev/description: Terraform configuration for Alibaba Cloud OSS object
  7. type: terraform
  8. spec:
  9. workload:
  10. definition:
  11. apiVersion: terraform.core.oam.dev/v1beta1
  12. kind: Configuration
  13. schematic:
  14. terraform:
  15. configuration: |
  16. resource "alicloud_oss_bucket" "bucket-acl" {
  17. bucket = var.bucket
  18. acl = var.acl
  19. }
  20. output "BUCKET_NAME" {
  21. value = "${alicloud_oss_bucket.bucket-acl.bucket}.${alicloud_oss_bucket.bucket-acl.extranet_endpoint}"
  22. }
  23. variable "bucket" {
  24. description = "OSS bucket name"
  25. default = "vela-website"
  26. type = string
  27. }
  28. variable "acl" {
  29. description = "OSS bucket ACL, supported 'private', 'public-read', 'public-read-write'"
  30. default = "private"
  31. type = string
  32. }