# --- 网络资源 --- resource "tencentcloud_vpc" "vpc" { name = "${local.project_prefix}-vpc" # 使用 local 变量 cidr_block = "10.0.0.0/16" tags = local.common_tags # 使用 local 变量 }
resource "tencentcloud_subnet" "subnet" { vpc_id = tencentcloud_vpc.vpc.id name = "${local.project_prefix}-subnet" # 使用 local 变量 cidr_block = "10.0.1.0/24" availability_zone = var.availability_zone tags = local.common_tags # 使用 local 变量 }
# --- 安全组资源 resource "tencentcloud_security_group" "base" { name = "${local.project_prefix}-sg" # Using local for consistency description = "Primary Security Group for VM" tags = local.common_tags }
resource "tencentcloud_security_group" "relative" { name = "${local.project_prefix}-sg-relative" # Using local for consistency description = "Used for attach security policy" tags = local.common_tags }
resource "tencentcloud_address_template" "foo" { name = "${local.project_prefix}-address-template" # Using local for consistency addresses = ["10.0.0.1", "10.0.1.0/24", "10.0.0.1-10.0.0.100"] }
resource "tencentcloud_address_template_group" "foo" { name = "${local.project_prefix}-address-template-group" # Using local for consistency template_ids = [tencentcloud_address_template.foo.id] }
# 输出为: Initializing the backend... Initializing provider plugins... - Finding tencentcloudstack/tencentcloud versions matching "1.82.29"... - Installing tencentcloudstack/tencentcloud v1.82.29... - Installed tencentcloudstack/tencentcloud v1.82.29 (signed by a HashiCorp partner, key ID 84F69E1C1BECF459) Partner and community providers are signed by their developers. If you'd like to know more about provider signing, you can read about it here: https://developer.hashicorp.com/terraform/cli/plugins/signing Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Include this file in your version control repository so that Terraform can guarantee to make the same selections by default when you run "terraform init" in the future. Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
# 输出为: data.tencentcloud_images.ubuntu_image: Reading... data.tencentcloud_instance_types.instance_type_s5: Reading... data.tencentcloud_images.ubuntu_image: Read complete after 1s [id=2198502367] data.tencentcloud_instance_types.instance_type_s5: Read complete after 1s [id=3046689892]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create
Terraform will perform the following actions:
# tencentcloud_address_template.foo will be created + resource "tencentcloud_address_template""foo" { + addresses = [ + "10.0.0.1", + "10.0.0.1-10.0.0.100", + "10.0.1.0/24", ] + id = (known after apply) + name = "tf-txy-demo-address-template" }
# tencentcloud_address_template_group.foo will be created + resource "tencentcloud_address_template_group""foo" { + id = (known after apply) + name = "tf-txy-demo-address-template-group" + template_ids = (known after apply) }
# tencentcloud_instance.my-vm will be created + resource "tencentcloud_instance""my-vm" { + allocate_public_ip = true + anti_ddos_package_id = (known after apply) + availability_zone = "ap-guangzhou-4" + cam_role_name = (known after apply) + cdh_host_id = (known after apply) + cdh_instance_type = (known after apply) + cpu = (known after apply) + create_time = (known after apply) + disable_api_termination = (known after apply) + disable_automation_service = false + disable_monitor_service = false + disable_security_service = false + expired_time = (known after apply) + force_delete = false + hostname = (known after apply) + hpc_cluster_id = (known after apply) + id = (known after apply) + image_id = "img-487zeit5" + instance_charge_type = "POSTPAID_BY_HOUR" + instance_charge_type_prepaid_renew_flag = (known after apply) + instance_name = "tf-txy-demo-vm" + instance_status = (known after apply) + instance_type = "S5.MEDIUM2" + internet_charge_type = (known after apply) + internet_max_bandwidth_out = (known after apply) + ipv4_address_type = (known after apply) + ipv6_address_count = (known after apply) + ipv6_address_type = (known after apply) + ipv6_addresses = (known after apply) + keep_image_login = (known after apply) + key_ids = (known after apply) + key_name = (known after apply) + memory = (known after apply) + orderly_security_groups = (known after apply) + os_name = (known after apply) + password = (sensitive value) + placement_group_id = (known after apply) + private_ip = (known after apply) + project_id = (known after apply) + public_ip = (known after apply) + public_ipv6_addresses = (known after apply) + running_flag = (known after apply) + security_groups = (known after apply) + subnet_id = (known after apply) + system_disk_id = (known after apply) + system_disk_name = (known after apply) + system_disk_size = 50 + system_disk_type = "CLOUD_PREMIUM" + tags = { + "CreatedBy" = "Terraform" + "Owner" = "Levitate Gu" } + user_data = (known after apply) + user_data_raw = (known after apply) + user_data_replace_on_change = false + uuid = (known after apply) + vpc_id = (known after apply)
+ data_disks (known after apply) }
# tencentcloud_security_group.base will be created + resource "tencentcloud_security_group""base" { + description = "Primary Security Group for VM" + id = (known after apply) + name = "tf-txy-demo-sg" + project_id = (known after apply) + tags = { + "CreatedBy" = "Terraform" + "Owner" = "Levitate Gu" } }
# tencentcloud_security_group.relative will be created + resource "tencentcloud_security_group""relative" { + description = "Used for attach security policy" + id = (known after apply) + name = "tf-txy-demo-sg-relative" + project_id = (known after apply) + tags = { + "CreatedBy" = "Terraform" + "Owner" = "Levitate Gu" } }
# tencentcloud_security_group_rule_set.base_rules will be created + resource "tencentcloud_security_group_rule_set""base_rules" { + id = (known after apply) + security_group_id = (known after apply) + version = (known after apply)
+ egress { + action = "DROP" + cidr_block = "10.0.0.0/16" + description = "A:Block ping3" + policy_index = (known after apply) + port = (known after apply) + protocol = "ICMP" } + egress { + action = "DROP" + address_template_id = (known after apply) + description = "B:Allow template" + policy_index = (known after apply) + port = (known after apply) + protocol = (known after apply) } + egress { + action = "DROP" + address_template_group = (known after apply) + description = "C:DROP template group" + policy_index = (known after apply) + port = (known after apply) + protocol = (known after apply) }
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
创建资源
1
terraform apply
遇到问题了:
1 2 3 4 5 6 7 8
╷ │ Error: [TencentCloudSDKError] Code=InvalidZone.MismatchRegion, Message=The specified zone ID `ap-guangzhou-4` does not match the region `ap-guangzhou`, RequestId=2a9433d0-a4c4-45cb-ac5a-161108dba7e6 │ │ with tencentcloud_instance.my-vm, │ on main.tf line 121, in resource "tencentcloud_instance""my-vm": │ 121: resource "tencentcloud_instance""my-vm" { │ ╵
╷ │ Error: [TencentCloudSDKError] Code=InvalidParameterCombination, Message=The combination of parameters between .InternetAccessible.PublicIpAssigned and InternetMaxBandwidthOut is incorrect, RequestId=878c5e48-57db-4991-849f-3fe2a5be502d │ │ with tencentcloud_instance.my-vm, │ on main.tf line 121, in resource "tencentcloud_instance""my-vm": │ 121: resource "tencentcloud_instance""my-vm" { │ ╵
data.tencentcloud_images.ubuntu_image: Reading... data.tencentcloud_instance_types.instance_type_s5: Reading... data.tencentcloud_images.ubuntu_image: Read complete after 1s [id=2198502367] data.tencentcloud_instance_types.instance_type_s5: Read complete after 1s [id=3086429807]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create
Terraform will perform the following actions:
# tencentcloud_address_template.foo will be created + resource "tencentcloud_address_template""foo" { + addresses = [ + "10.0.0.1", + "10.0.0.1-10.0.0.100", + "10.0.1.0/24", ] + id = (known after apply) + name = "tf-txy-demo-address-template" }
# tencentcloud_address_template_group.foo will be created + resource "tencentcloud_address_template_group""foo" { + id = (known after apply) + name = "tf-txy-demo-address-template-group" + template_ids = (known after apply) }
# tencentcloud_instance.my-vm will be created + resource "tencentcloud_instance""my-vm" { + allocate_public_ip = true + anti_ddos_package_id = (known after apply) + availability_zone = "ap-guangzhou-6" + cam_role_name = (known after apply) + cdh_host_id = (known after apply) + cdh_instance_type = (known after apply) + cpu = (known after apply) + create_time = (known after apply) + disable_api_termination = (known after apply) + disable_automation_service = false + disable_monitor_service = false + disable_security_service = false + expired_time = (known after apply) + force_delete = false + hostname = (known after apply) + hpc_cluster_id = (known after apply) + id = (known after apply) + image_id = "img-487zeit5" + instance_charge_type = "POSTPAID_BY_HOUR" + instance_charge_type_prepaid_renew_flag = (known after apply) + instance_name = "tf-txy-demo-vm" + instance_status = (known after apply) + instance_type = "S5.MEDIUM4" + internet_charge_type = (known after apply) + internet_max_bandwidth_out = 3 + ipv4_address_type = (known after apply) + ipv6_address_count = (known after apply) + ipv6_address_type = (known after apply) + ipv6_addresses = (known after apply) + keep_image_login = (known after apply) + key_ids = (known after apply) + key_name = (known after apply) + memory = (known after apply) + orderly_security_groups = (known after apply) + os_name = (known after apply) + password = (sensitive value) + placement_group_id = (known after apply) + private_ip = (known after apply) + project_id = (known after apply) + public_ip = (known after apply) + public_ipv6_addresses = (known after apply) + running_flag = (known after apply) + security_groups = (known after apply) + subnet_id = (known after apply) + system_disk_id = (known after apply) + system_disk_name = (known after apply) + system_disk_size = 50 + system_disk_type = "CLOUD_PREMIUM" + tags = { + "CreatedBy" = "Terraform" + "Owner" = "Levitate Gu" } + user_data = (known after apply) + user_data_raw = (known after apply) + user_data_replace_on_change = false + uuid = (known after apply) + vpc_id = (known after apply)
+ data_disks (known after apply) }
# tencentcloud_security_group.base will be created + resource "tencentcloud_security_group""base" { + description = "Primary Security Group for VM" + id = (known after apply) + name = "tf-txy-demo-sg" + project_id = (known after apply) + tags = { + "CreatedBy" = "Terraform" + "Owner" = "Levitate Gu" } }
# tencentcloud_security_group.relative will be created + resource "tencentcloud_security_group""relative" { + description = "Used for attach security policy" + id = (known after apply) + name = "tf-txy-demo-sg-relative" + project_id = (known after apply) + tags = { + "CreatedBy" = "Terraform" + "Owner" = "Levitate Gu" } }
# tencentcloud_security_group_rule_set.base_rules will be created + resource "tencentcloud_security_group_rule_set""base_rules" { + id = (known after apply) + security_group_id = (known after apply) + version = (known after apply)
+ egress { + action = "DROP" + cidr_block = "10.0.0.0/16" + description = "A:Block ping3" + policy_index = (known after apply) + port = (known after apply) + protocol = "ICMP" } + egress { + action = "DROP" + address_template_id = (known after apply) + description = "B:Allow template" + policy_index = (known after apply) + port = (known after apply) + protocol = (known after apply) } + egress { + action = "DROP" + address_template_group = (known after apply) + description = "C:DROP template group" + policy_index = (known after apply) + port = (known after apply) + protocol = (known after apply) }
# --- 网络资源 --- resource "tencentcloud_vpc" "vpc" { name = "${local.project_prefix}-vpc" # 使用 local 变量 cidr_block = "10.0.0.0/16" tags = local.common_tags # 使用 local 变量 }
resource "tencentcloud_subnet" "subnet" { vpc_id = tencentcloud_vpc.vpc.id name = "${local.project_prefix}-subnet" # 使用 local 变量 cidr_block = "10.0.1.0/24" availability_zone = var.availability_zone tags = local.common_tags # 使用 local 变量 }
# --- 安全组资源 resource "tencentcloud_security_group" "base" { name = "${local.project_prefix}-sg" # Using local for consistency description = "Primary Security Group for VM" tags = local.common_tags }
resource "tencentcloud_security_group" "relative" { name = "${local.project_prefix}-sg-relative" # Using local for consistency description = "Used for attach security policy" tags = local.common_tags }
resource "tencentcloud_address_template" "foo" { name = "${local.project_prefix}-address-template" # Using local for consistency addresses = ["10.0.0.1", "10.0.1.0/24", "10.0.0.1-10.0.0.100"] }
resource "tencentcloud_address_template_group" "foo" { name = "${local.project_prefix}-address-template-group" # Using local for consistency template_ids = [tencentcloud_address_template.foo.id] }