terraform -version
Terraform v1.3.0on darwin_amd64Your version of Terraform is out of date! The latest versionis 1.3.2. You can update by downloading from https://www.terraform.io/downloads.html
provider.tf
文件,输入如下内容:provider "tencentcloud" {secret_id = "my-secret-id"secret_key = "my-secret-key"}
export TENCENTCLOUD_SECRET_ID=YOUR_SECRET_IDexport TENCENTCLOUD_SECRET_KEY=YOUR_SECRET_KEY
terraform {required_providers {tencentcloud = {source = "tencentcloudstack/tencentcloud"# 通过version指定版本# version = ">=1.60.18"}}}provider "tencentcloud" {region = "ap-guangzhou"# secret_id = "my-secret-id"# secret_key = "my-secret-key"}
resource "tencentcloud_vpc" "foo" {name = "ci-temp-test-updated"cidr_block = "10.0.0.0/16"dns_servers = ["119.29.29.29", "8.8.8.8"]is_multicast = falsetags = {"test" = "test"}}
terraform init
➜ terraform_workspace terraform initInitializing the backend...Initializing provider plugins...- Finding latest version of tencentcloudstack/tencentcloud...- Installing tencentcloudstack/tencentcloud v1.60.18...- Installed tencentcloudstack/tencentcloud v1.60.18 (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://www.terraform.io/docs/cli/plugins/signing.htmlTerraform has created a lock file .terraform.lock.hcl to record the providerselections it made above. Include this file in your version control repositoryso that Terraform can guarantee to make the same selections by default whenyou run "terraform init" in the future.Terraform has been successfully initialized!You may now begin working with Terraform. Try running "terraform plan" to seeany changes that are required for your infrastructure. All Terraform commandsshould 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, othercommands will detect it and remind you to do so if necessary.
terraform init -upgrade
➜ terraform_workspace terraform init -upgradeInitializing the backend...Initializing provider plugins...- Finding tencentcloudstack/tencentcloud versions matching ">= 1.60.18"...- Installing tencentcloudstack/tencentcloud v1.60.19...- Installed tencentcloudstack/tencentcloud v1.60.19 (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://www.terraform.io/docs/cli/plugins/signing.htmlTerraform has made some changes to the provider dependency selections recordedin the .terraform.lock.hcl file. Review those changes and commit them to yourversion control system if they represent changes you intended to make.Terraform has been successfully initialized!You may now begin working with Terraform. Try running "terraform plan" to seeany changes that are required for your infrastructure. All Terraform commandsshould 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, othercommands will detect it and remind you to do so if necessary.
terraform plan
➜ terraform_workspace terraform planTerraform used the selected providers to generate the following execution plan. Resource actions areindicated with the following symbols:+ createTerraform will perform the following actions:# tencentcloud_vpc.foo will be created+ resource "tencentcloud_vpc" "foo" {+ cidr_block = "10.0.0.0/16"+ create_time = (known after apply)+ default_route_table_id = (known after apply)+ dns_servers = [+ "119.29.29.29",+ "8.8.8.8",]+ id = (known after apply)+ is_default = (known after apply)+ is_multicast = false+ name = "ci-temp-test-updated"+ tags = {+ "test" = "test"}}Plan: 1 to add, 0 to change, 0 to destroy.─────────────────────────────────────────────────────────────────────────────────────────────────────────────Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly theseactions if you run "terraform apply" now.
terraform apply
➜ terraform_workspace terraform applyTerraform used the selected providers to generate the following execution plan. Resource actions areindicated with the following symbols:+ createTerraform will perform the following actions:# tencentcloud_vpc.foo will be created+ resource "tencentcloud_vpc" "foo" {+ cidr_block = "10.0.0.0/16"+ create_time = (known after apply)+ default_route_table_id = (known after apply)+ dns_servers = [+ "119.29.29.29",+ "8.8.8.8",]+ id = (known after apply)+ is_default = (known after apply)+ is_multicast = false+ name = "ci-temp-test-updated"+ tags = {+ "test" = "test"}}Plan: 1 to add, 0 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: yestencentcloud_vpc.foo: Creating...tencentcloud_vpc.foo: Still creating... [10s elapsed]tencentcloud_vpc.foo: Creation complete after 13s [id=vpc-07mx4yfd]Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
resource "tencentcloud_vpc" "foo" {name = "ci-temp-test-updated2"cidr_block = "10.0.0.0/16"dns_servers = ["119.29.29.29", "8.8.8.8"]is_multicast = falsetags = {"test" = "test"}}
terraform plan
命令更新计划。返回信息如下所示:➜ terraform_workspace terraform plantencentcloud_vpc.foo: Refreshing state... [id=vpc-jhmdf9q9]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:~ update in-placeTerraform will perform the following actions:# tencentcloud_vpc.foo will be updated in-place~ resource "tencentcloud_vpc" "foo" {id = "vpc-jhmdf9q9"~ name = "ci-temp-test-updated" -> "ci-temp-test-updated2"tags = {"test" = "test"}# (6 unchanged attributes hidden)}Plan: 0 to add, 1 to change, 0 to destroy.───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────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.
terraform apply
命令,应用更新的数据创建资源。返回信息如下:➜ terraform_workspace terraform applytencentcloud_vpc.foo: Refreshing state... [id=vpc-jhmdf9q9]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:~ update in-placeTerraform will perform the following actions:# tencentcloud_vpc.foo will be updated in-place~ resource "tencentcloud_vpc" "foo" {id = "vpc-jhmdf9q9"~ name = "ci-temp-test-updated" -> "ci-temp-test-updated2"tags = {"test" = "test"}# (6 unchanged attributes hidden)}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: yestencentcloud_vpc.foo: Modifying... [id=vpc-jhmdf9q9]tencentcloud_vpc.foo: Modifications complete after 1s [id=vpc-jhmdf9q9]Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
terraform destroy
➜ terraform_workspace terraform destroytencentcloud_vpc.foo: Refreshing state... [id=vpc-07mx4yfd]Terraform used the selected providers to generate the following execution plan. Resource actions areindicated with the following symbols:- destroyTerraform will perform the following actions:# tencentcloud_vpc.foo will be destroyed- resource "tencentcloud_vpc" "foo" {- cidr_block = "10.0.0.0/16" -> null- create_time = "2021-12-15 16:20:32" -> null- default_route_table_id = "rtb-4m1nmo0e" -> null- dns_servers = [- "119.29.29.29",- "8.8.8.8",] -> null- id = "vpc-07mx4yfd" -> null- is_default = false -> null- is_multicast = false -> null- name = "ci-temp-test-updated" -> null- tags = {- "test" = "test"} -> null}Plan: 0 to add, 0 to change, 1 to destroy.Do you really want to destroy all resources?Terraform will destroy all your managed infrastructure, as shown above.There is no undo. Only 'yes' will be accepted to confirm.Enter a value: yestencentcloud_vpc.foo: Destroying... [id=vpc-07mx4yfd]tencentcloud_vpc.foo: Destruction complete after 7sDestroy complete! Resources: 1 destroyed.
本页内容是否解决了您的问题?