Terraform을 사용하여 Alibaba Cloud에서 PostgreSQL용 ECS+RDS를 생성하는 방법
https://youtu.be/O0X02sPwHL8
[문서]
https://www.alibabacloud.com/help/resource-access-management/latest/obtain-an-accesskey-pair-2
데모:
https://youtu.be/XYPBmT8UgzM
사용해 보시겠습니까? 아래 샘플을 확인하십시오.
provider "alicloud" {
access_key = "your_AK"
secret_key = "your_SK"
region = "eu-west-1"
}
variable "zone_1" {
default = "eu-west-1b"
}
variable "name" {
default = "test_group"
}
######## Security group
resource "alicloud_security_group" "group" {
name = "pg_test"
description = "Security group for test"
vpc_id = alicloud_vpc.vpc.id
}
resource "alicloud_security_group_rule" "allow_https_443" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "443/443"
priority = 1
security_group_id = alicloud_security_group.group.id
cidr_ip = "0.0.0.0/0"
}
resource "alicloud_security_group_rule" "allow_ssh_22" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "22/22"
priority = 1
security_group_id = alicloud_security_group.group.id
cidr_ip = "0.0.0.0/0"
}
resource "alicloud_security_group_rule" "allow_rdp_3389" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "3389/3389"
priority = 1
security_group_id = alicloud_security_group.group.id
cidr_ip = "0.0.0.0/0"
}
resource "alicloud_security_group_rule" "allow_all_icmp" {
type = "ingress"
ip_protocol = "icmp"
nic_type = "intranet"
policy = "accept"
port_range = "-1/-1"
priority = 1
security_group_id = alicloud_security_group.group.id
cidr_ip = "0.0.0.0/0"
}
######## VPC
resource "alicloud_vpc" "vpc" {
vpc_name = var.name
cidr_block = "192.168.0.0/16"
}
resource "alicloud_vswitch" "vswitch_1" {
vpc_id = alicloud_vpc.vpc.id
cidr_block = "192.168.0.0/24"
zone_id = var.zone_1
vswitch_name = "vsw_on_zone_1"
}
######## ECS
resource "alicloud_instance" "instance" {
security_groups = alicloud_security_group.group.*.id
# series III
instance_type = "ecs.c5.large" # 2core 4GB
system_disk_category = "cloud_ssd"
system_disk_name = "system_disk"
system_disk_size = 40
system_disk_description = "system_disk"
image_id = "centos_8_3_x64_20G_alibase_20210723.vhd"
instance_name = "test_ecs"
password = "Passw@rd"
instance_charge_type = "PostPaid"
vswitch_id = alicloud_vswitch.vswitch_1.id
data_disks {
name = "disk2"
size = 100
category = "cloud_efficiency"
description = "disk2"
}
}
######## EIP bind to setup ECS accessing from internet
resource "alicloud_eip" "setup_ecs_access" {
bandwidth = "5"
internet_charge_type = "PayByBandwidth"
}
resource "alicloud_eip_association" "eip_ecs" {
allocation_id = alicloud_eip.setup_ecs_access.id
instance_id = alicloud_instance.instance.id
}
######## RDS PostgreSQL
resource "alicloud_db_instance" "instance" {
engine = "PostgreSQL"
engine_version = "14.0"
instance_type = "pg.n2.small.1"
instance_storage = "20"
vswitch_id = alicloud_vswitch.vswitch_1.id
instance_name = "rds_pg_test_instance"
security_ips = [alicloud_vswitch.vswitch_1.cidr_block]
}
resource "alicloud_db_database" "default" {
instance_id = alicloud_db_instance.instance.id
name = "testdb"
}
resource "alicloud_rds_account" "account" {
db_instance_id = alicloud_db_instance.instance.id
account_name = "test1"
account_password = "test123"
account_type = "Super"
}
resource "alicloud_db_account_privilege" "privilege" {
instance_id = alicloud_db_instance.instance.id
account_name = alicloud_rds_account.account.name
privilege = "DBOwner"
db_names = alicloud_db_database.default.*.name
}
######### Output: EIP of ECS
output "eip_ecs" {
value = alicloud_eip.setup_ecs_access.ip_address
}
######### Output: RDS PostgreSQL Connection String
output "rds_pg_url" {
value = alicloud_db_instance.instance.connection_string
}
######### Output: RDS PostgreSQL Connection Port
output "rds_pg_port" {
value = alicloud_db_instance.instance.port
}
Reference
이 문제에 관하여(Terraform을 사용하여 Alibaba Cloud에서 PostgreSQL용 ECS+RDS를 생성하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/mrboogiej/how-to-create-ecsrds-for-postgresql-on-alibaba-cloud-using-terraform-1hde텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)