DaaS / Products / Deploy Stack, Lock Down DB, Verify Connectivity

Deploy Stack, Lock Down DB, Verify Connectivity

A DevOps team provisions a full production web stack via Terraform, configures granular multi-tier RDS accounts and role-based permissions (app, analytics, admin), then systematically debugs and verifies database connectivity for each configured role to ensure least-privilege access works end-to-end.

Products involved

Scenario

This workflow is required when DevOps teams must automate the provisioning of a production web stack while enforcing strict, role-based database access controls. It bridges infrastructure-as-code deployment with granular RDS account configuration and systematic connectivity validation to guarantee least-privilege compliance before production cutover.

Integration steps

  1. Initialize Terraform & Provider: Create main.tf with provider "alicloud" { region = "cn-hangzhou" }. Run terraform init.
  2. Provision Core Stack: Define alicloud_vpc, alicloud_instance (ALinux 3), alicloud_db_instance (MySQL 8.0), and alicloud_oss_bucket. Apply via terraform apply -auto-approve.
  3. Bind CAS SSL to SLB: Upload your CAS certificate using alicloud_slb_certificate. Attach to alicloud_slb_listener with frontend_port = 443, backend_port = 80, and protocol = "https".
  4. Create Multi-Tier RDS Accounts: Provision accounts via alicloud_db_account for app_rw, analytics_ro, and admin. Assign privileges using alicloud_db_account_privilege (ReadWrite, ReadOnly, DBA respectively).
  5. Lock Down Network Access: Define alicloud_security_group_rule to allow ECS private IP to RDS port 3306. Update RDS whitelist via alicloud_db_instance ip_list = ["${alicloud_instance.web.private_ip}/32"].
  6. Verify & Debug Connectivity: SSH into ECS. Test each role sequentially:
  7. ``bash nc -zv <rds_endpoint> 3306 # Verify network reachability mysql -h <rds_endpoint> -u app_rw -p -e "INSERT INTO logs VALUES(1);" # Expect success mysql -h <rds_endpoint> -u analytics_ro -p -e "INSERT INTO logs VALUES(1);" # Expect ERROR 1142 (Access denied) ``

  8. Automate API Validation: Query RDS API to confirm state:
  9. ``bash curl -X POST "https://rds.aliyuncs.com/?Action=DescribeAccounts&DBInstanceId=<id>&Format=JSON" ` Cross-reference AccountStatus and AccountPrivilege` against expected values.

Architecture

Terraform orchestrates the entire lifecycle. Inbound HTTPS traffic terminates at an SLB using a CAS-managed certificate, then routes to an ALinux-based ECS cluster. ECS instances serve application logic, fetch static assets from OSS, and execute database queries against RDS. RDS enforces granular, role-based access via dedicated accounts, while VPC routing and security groups isolate compute, storage, and database tiers.

Prerequisites

Common pitfalls

Typical questions