-- 1. VPC、VSwitch作成
cat <<-'EOF' > variables.tf
locals {
availability_zone = "ap-northeast-1a"
}
EOF
cat <<-'EOF' > main.tf
terraform {
required_version = ">= 1.0.0, < 2.0.0"
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "= 1.217.0"
}
}
}
provider "alicloud" {
region = "ap-northeast-1"
}
resource "alicloud_vpc" "vpc01" {
vpc_name = "vpc01"
description = "vpc01"
cidr_block = "10.2.0.0/16"
}
resource "alicloud_vswitch" "sw01" {
vswitch_name = "sw01"
description = "sw01"
vpc_id = alicloud_vpc.vpc01.id
cidr_block = "10.2.1.0/24"
zone_id = local.availability_zone
}
resource "alicloud_security_group" "sg01" {
name = "sg01"
description = "sg01"
vpc_id = alicloud_vpc.vpc01.id
security_group_type = "normal"
}
resource "alicloud_security_group_rule" "sg0101" {
type = "ingress"
ip_protocol = "tcp"
port_range = "3306/3306"
security_group_id = alicloud_security_group.sg01.id
nic_type = "intranet"
policy = "accept"
priority = 10
cidr_ip = "10.2.1.0/24"
description = "sg0101"
}
EOF
cat <<-'EOF' > outputs.tf
output "vpc01_id" {
value = alicloud_vpc.vpc01.id
description = "vpc01.id"
}
output "sw01_id" {
value = alicloud_vswitch.sw01.id
description = "sw01.id"
}
output "sg01_id" {
value = alicloud_security_group.sg01.id
description = "sg01.id"
}
EOF
terraform init
terraform fmt
terraform -version
terraform plan
terraform apply -auto-approve
# terraform destroy -auto-approve
-- 2. RDSインスタンス作成
aliyun rds DescribeDBInstances
aliyun rds CreateDBInstance \
--DBInstanceClass mysql.n2e.small.1 \
--DBInstanceNetType Intranet \
--DBInstanceStorage 20 \
--Engine MySQL \
--EngineVersion 8.0 \
--PayType Postpaid \
--Category Basic \
--ConnectionMode Standard \
--DBInstanceStorageType cloud_essd \
--DBIsIgnoreCase true \
--DBTimeZone "+9:00" \
--DeletionProtection false \
--Port 3306 \
--StorageAutoScale Disable \
--InstanceNetworkType VPC \
--VPCId vpc-111111111111111111111 \
--VSwitchId vsw-111111111111111111111 \
--ZoneId ap-northeast-1a \
--DBInstanceDescription instance01 \
--SecurityIPList "10.2.0.0/16" \
--read-timeout 120 \
--connect-timeout 120
RDSインスタンス削除
aliyun rds DeleteDBInstance \
--DBInstanceId rm-11111111111111111
-- 3. インスタンスタイプ変更
aliyun rds ListClasses \
--CommodityCode bards_intl \
--OrderType BUY
aliyun rds ListClasses \
--CommodityCode bards_intl \
--OrderType BUY \
| jq -c ".Items[] | [.ClassCode, .Cpu, .MemoryClass, .InstructionSetArch]"
aliyun rds DescribeDBInstances
aliyun rds ModifyDBInstanceSpec \
--DBInstanceId rm-11111111111111111 \
--DBInstanceClass mysql.n2e.medium.1