3. 使用Terraform修改资源 (阿里云)
1. 设置token
[root@test01 terraform]# export ALICLOUD_ACCESS_KEY="LTAIUrZCw3********" [root@test01 terraform]# export ALICLOUD_SECRET_KEY="zfwwWAMWIAiooj14GQ2*************" [root@test01 terraform]# export ALICLOUD_REGION="cn-beijing"
2. 修改ECS实例
1) 在terraform的任务文件中增加
|
[root@test01 terraform]# cat example.tf # 修改实例类型 resource "alicloud_instance" "instance" { # cn-beijing availability_zone = "cn-beijing-b" security_groups = ["${alicloud_security_group.default.id}"]
# series III instance_type = "ecs.n2.small" instance_type = "ecs.n2.medium" system_disk_category = "cloud_efficiency" image_id = "ubuntu_140405_64_40G_cloudinit_20161115.vhd" instance_name = "test_foo" vswitch_id = "${alicloud_vswitch.vsw.id}" internet_max_bandwidth_out =10 password = "<replace_with_your_password>" } |
|
[root@test01 terraform]# ./terraform apply alicloud_vpc.vpc: Refreshing state... [id=vpc-2zehf5gn63vksdtt1dgl8] alicloud_vswitch.vsw: Refreshing state... [id=vsw-2zexuzjz78g1rjpv1xgmi] alicloud_security_group.default: Refreshing state... [id=sg-2zeaao13ppsw7hguq2cw] alicloud_security_group_rule.allow_all_tcp: Refreshing state... [id=sg-2zeaao13ppsw7hguq2cw:ingress:tcp:1/65535:intranet:0.0.0.0/0:accept:1] alicloud_instance.instance: Refreshing state... [id=i-2zefuy5y5pf2fuxw4m41]
An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: ~ update in-place
Terraform will perform the following actions:
# alicloud_instance.instance will be updated in-place ~ resource "alicloud_instance" "instance" { availability_zone = "cn-beijing-b" deletion_protection = false host_name = "iZ2zefuy5y5pf2fuxw4m41Z" id = "i-2zefuy5y5pf2fuxw4m41" image_id = "ubuntu_140405_64_40G_cloudinit_20161115.vhd" instance_charge_type = "PostPaid" instance_name = "test_foo" ~ instance_type = "ecs.n2.small" -> "ecs.n2.medium" internet_charge_type = "PayByTraffic" internet_max_bandwidth_in = -1 internet_max_bandwidth_out = 10 password = (sensitive value) private_ip = "172.16.2.197" public_ip = "**.**.**.**" security_groups = [ "sg-2zeaao13ppsw7hguq2cw", ] spot_price_limit = 0 spot_strategy = "NoSpot" status = "Running" subnet_id = "vsw-2zexuzjz78g1rjpv1xgmi" system_disk_category = "cloud_efficiency" system_disk_size = 40 volume_tags = {} vswitch_id = "vsw-2zexuzjz78g1rjpv1xgmi" }
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.
Enter a value: yes
alicloud_instance.instance: Modifying... [id=i-2zefuy5y5pf2fuxw4m41] alicloud_instance.instance: Still modifying... [id=i-2zefuy5y5pf2fuxw4m41, 10s elapsed] alicloud_instance.instance: Still modifying... [id=i-2zefuy5y5pf2fuxw4m41, 20s elapsed]
Error: [ERROR] terraform-provider-alicloud/alicloud/resource_alicloud_instance.go:630: [ERROR] terraform-provider-alicloud/alicloud/resource_alicloud_instance.go:1255: Resource i-2zefuy5y5pf2fuxw4m41 ModifyInstanceSpec Failed!!! [SDK alibaba-cloud-sdk-go ERROR]: SDK.ServerError ErrorCode: InvalidAccountStatus.NotEnoughBalance Recommend: RequestId: 72136731-CF9C-42FD-8B25-3F7ACDF5EC90 Message: Your account does not have enough balance.
on example.tf line 30, in resource "alicloud_instance" "instance": 30: resource "alicloud_instance" "instance" { PS: 由于费用不足,产生报错,实际可以正常使用。
[root@test01 terraform]# |
|
[root@test01 terraform]# ./terraform show |

浙公网安备 33010602011771号