DaaS / Products / CI/CD-Automated Secure Web Stack Deployment

CI/CD-Automated Secure Web Stack Deployment

A DevOps team establishes Terraform CI/CD automation to continuously deploy and maintain a production web stack (VPC, ECS cluster, OSS, SLB) with SSL certificates and security hardening, enabling secure infrastructure updates through automated pipelines.

Products involved

Scenario

This workflow is essential for DevOps teams requiring zero-touch, auditable deployments of production-grade web applications. By integrating Terraform with ECS, OSS, SLB, and CAS within a CI/CD pipeline, teams can automatically provision hardened infrastructure, attach SSL certificates, and enforce security policies on every code commit.

Integration steps

  1. Initialize Terraform & Auth: Configure the Alibaba Cloud provider with RAM credentials. Store secrets in CI/CD variables (ALICLOUD_ACCESS_KEY, ALICLOUD_SECRET_KEY).
  2. ``hcl provider "alicloud" { region = "cn-shanghai" access_key = var.access_key secret_key = var.secret_key } ``

  3. Provision Network & Load Balancer: Define VPC, VSwitch, and SLB. Attach a security group allowing only ports 80/443.
  4. ``hcl resource "alicloud_slb" "web_lb" { name = "prod-web-lb" vswitch_id = alicloud_vswitch.main.id address_type = "internet" bandwidth = 10 } ``

  5. Deploy ECS & OSS with Hardening: Launch ECS instances with an instance RAM role. Create an OSS bucket and enforce anti-hotlinking via Referer configuration.
  6. ``hcl resource "alicloud_oss_bucket" "assets" { bucket = "prod-static-assets" referer_config { allow_empty = false referers = ["https://*.example.com"] } } ``

  7. Bind CAS SSL Certificate: Reference your CAS-managed certificate ARN and attach it to the SLB HTTPS listener.
  8. ``hcl resource "alicloud_slb_listener" "https" { load_balancer_id = alicloud_slb.web_lb.id backend_port = 80 frontend_port = 443 protocol = "https" server_certificate_id = var.cas_cert_arn } ``

  9. Automate via CI/CD Pipeline: Configure your pipeline (e.g., GitLab CI) to run terraform init, terraform plan -out=tfplan, and terraform apply tfplan on main branch merges. Use an OSS backend for remote state.
  10. Validate Deployment: Trigger a pipeline run. Verify ECS health checks pass, SLB routes HTTPS traffic, and OSS bucket policies reject unauthorized requests.

Architecture

The CI/CD runner acts as the execution engine, pulling Terraform configurations from Git and invoking the Alibaba Cloud Provider API. Terraform orchestrates resource creation: VPC/SLB handles traffic routing, ECS runs application workloads, OSS stores static assets, and CAS supplies the X.509 certificate to the SLB listener. State is persisted in a remote OSS backend with locking to prevent concurrent modifications.

Prerequisites

Common pitfalls

Typical questions

FAQ

Q: How can I automate the deployment of a secure HTTPS web stack with SSL certificates and security hardening using Terraform and CI/CD? A: The solution leverages Terraform CI/CD automation to continuously deploy and maintain a production web stack that includes VPC, ECS clusters, OSS, SLB, SSL certificates, and security hardening. It enables secure infrastructure updates through automated pipelines by utilizing integrated skill combinations like Terraform Secure Web Stack with SSL and Terraform Full-Stack Deploy with Security Hardening.