ecs
%appdata%\terraform.rc
provider_installation {
filesystem_mirror {
path = “C:/Users/Linus/tf/mirror”
}
}
main.cf
provider “alicloud” {
access_key = “xxxxxxxxxxxxxxxx”
secret_key = “xxxxxxxxxxxxxxxx”
region = “cn-beijing”
}
resource “alicloud_vpc” “testvpc” {
vpc_name = “testvpc”
cidr_block = “192.168.0.0/16”
}
resource “alicloud_vswitch” “vswitch” {
vpc_id = alicloud_vpc.testvpc.id
cidr_block = “192.168.100.0/24”
zone_id = “cn-beijing-d”
}
resource “alicloud_security_group” “testgroup” {
name = “sg-test”
description = “test security group”
vpc_id = “${alicloud_vpc.testvpc.id}”
}
resource “alicloud_security_group_rule” “allow_22” {
type = “ingress”
ip_protocol = “tcp”
nic_type = “intranet”
policy = “accept”
port_range = “22/22”
priority = 1
security_group_id = “${alicloud_security_group.testgroup.id}”
cidr_ip = “10.56.8.13/32”
}
resource “alicloud_instance” “test” {
description = “test”
host_name = “test”
image_id = “ubuntu_20_04_x64_20G_alibase_20220727.vhd”
instance_name = “test”
instance_charge_type = “PostPaid”
security_groups = alicloud_security_group.testgroup.*.id
instance_type = “ecs.xn4.small”
vswitch_id = alicloud_vswitch.vswitch.id
internet_charge_type = “PayByBandwidth”
internet_max_bandwidth_out = 1
}
terraform init
terraform show
terraform plan
terraform state pull
terraform import alicloud_security_group_rule.allow_22 sg-2zefwtrsg4df3r4cy80:ingress:tcp:22/22:intranet:x.x.x.x/32:accept:2