args:- name: app_certificationlabel: SSL Certificateswidget: certificate-selectoptional: true- name: app_domainlabel: domain namewidget: domain-inputoptional: truecertId: ${app_certification.certId}
variable "app_certification" {type = object({certId = string})}variable "app_domain" {type = object({domain = string})}
# Declare a CLB instanceresource "tencentcloud_clb_instance" "open_clb" {# Network type of the load balancing instance. OPEN: public network. INTERNAL: private network.network_type = "OPEN"# Security groupsecurity_groups = [var.sg.security_group.id]# VPCvpc_id = var.app_target.vpc.id# Subnetsubnet_id = var.app_target.subnet.id# Enable default pass-through, that is, the Target allows traffic from the CLB.load_balancer_pass_to_target = true}# Declare a CLB HTTPS listenerresource "tencentcloud_clb_listener" "https_listener" {clb_id = tencentcloud_clb_instance.open_clb.idlistener_name = "https_listener"# CLB listens on port 443, support HTTPS accessport = 443protocol = "HTTPS"# Use the certificate declared in the installation parameters herecertificate_id = var.app_certification.certIdcertificate_ssl_mode = "UNIDIRECTIONAL"}# Declare a CLB forwarding ruleresource "tencentcloud_clb_listener_rule" "https_rule" {clb_id = tencentcloud_clb_instance.open_clb.idlistener_id = tencentcloud_clb_listener.https_listener.id# Configure this as the domain name declared in the installation parameters. It means that when the request is a domain name request, forward it.domain = var.app_domain.domain# Which path to forward. Here, configure the root path for site-wide forwarding.url = "/"}# Declare a CLB backend service binding to forward the traffic that hits the forwarding rule to the CVM.resource "tencentcloud_clb_attachment" "clb_backend" {clb_id = tencentcloud_clb_instance.open_clb.idlistener_id = tencentcloud_clb_listener.https_listener.idrule_id = tencentcloud_clb_listener_rule.api_https_rule.idtargets {# CVM instance ID (replace with the actual instance ID)instance_id = tencentcloud_instance.demo_cvm[0].id# Assume our CVM has an open http port 3000.port = 3000# weightweight = 100}}
Feedback