Terraform 基础设施管理工具

1,164次阅读
一条评论

共计 21059 个字符,预计需要花费 53 分钟才能阅读完成。

Terraform 基础设施管理工具

Terraform简介

Terraform是一个开源用于资源编排管理的自动化工具。 Infrastructure as Code ,以代码的形式将所要管理的资源定义在模板中,通过解析并执行模板来自动化完成所定义资源的创建、变更和管理。以往博主交付某个项目都是人工创建基础资源,然后再用Ansible等工具进行应用程序部署,为了缩短交付时间,则使用terraform工具来创建基础资源,真香~

  • 复用性:基于文件声明和变量控制,轻松复用
  • 幂等性:可重复执行,结果一致
  • 可审计:审计和版本控制

Terraform安装

Terraform安装

[root@node-nfs vpc_terraform]# yum install -y yum-utils
[root@node-nfs vpc_terraform]# yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
[root@node-nfs vpc_terraform]# yum -y install terraform
[root@node-nfs vpc_terraform]# terraform version
Terraform v1.1.9
on linux_amd64

下载Provider

terraform每个项目需要定义provider.tf,在该文件中定义需要使用provider,当使用terraform初始化时则会根据定义下载相应provider至项目目录下。因为是从github上下载,其龟速可想而知,容器报超时

[root@node-nfs vpc_terraform]# cat providers.tf 
terraform {
  required_providers {
    alicloud = {
      source = "aliyun/alicloud"
      version = "1.166.0"
    }
  }
}

provider "alicloud" {
  access_key = "xxx"
  secret_key = "xxx"
  region = "cn-shenzhen"
}
[root@node-nfs vpc_terraform]# terraform init

Initializing the backend...

Initializing provider plugins...
- Finding aliyun/alicloud versions matching "1.166.0"...
╷
│ Error: Failed to install provider
│ 
│ Error while installing aliyun/alicloud v1.166.0: could not query provider registry for registry.terraform.io/aliyun/alicloud: failed to retrieve authentication checksums for provider: the request failed after 2 attempts, please try again later: Get
│ "https://github.com/aliyun/terraform-provider-alicloud/releases/download/v1.166.0/terraform-provider-alicloud_1.166.0_SHA256SUMS": read tcp 192.168.174.135:39960->20.205.243.166:443: read: connection reset by peer
╵

为了提高后续方便多项目复用,博主不得已使用本地仓临时取缔下

本地仓库的前提是需要读者自行提前下载好provider~,然后再项目中定义本地仓库引用,从而提高复用性,不用每次都要下

创建本地仓库

创建本地仓库目录

# 创建本地仓库
[root@node-nfs vpc_terraform]# mkdir -p ~/.terraform.d/plugins/local-registry

提前拿点数据

# 翻个跟斗拿点数据~
[root@node-nfs vpc_terraform]# terraform init

Initializing the backend...

Initializing provider plugins...
- Finding aliyun/alicloud versions matching "1.166.0"...
- Installing aliyun/alicloud v1.166.0...
- Installed aliyun/alicloud v1.166.0 (signed by a HashiCorp partner, key ID 47422B4AA9FA381B)

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.html

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.

# 查看刚才下载的provider
# [root@node-nfs vpc_terraform]# 
[root@node-nfs vpc_terraform]# tree -a
.
├── providers.tf
├── .terraform
│   └── providers
│       └── registry.terraform.io
│           └── aliyun
│               └── alicloud
│                   └── 1.166.0
│                       └── linux_amd64
│                           └── terraform-provider-alicloud_v1.166.0
└── .terraform.lock.hcl

7 directories, 3 files

移动provider到本地仓库

# [root@node-nfs vpc_terraform]# cp -rp .terraform/providers/registry.terraform.io/aliyun/ ~/.terraform.d/plugins/local-registry

测试引用本地仓库

# 修改项目provider引用位置
[root@node-nfs vpc_terraform]# cat >providers.tf<<'EOF'
terraform {
  required_providers {
    alicloud = {
      #source = "aliyun/alicloud"
      source = "local-registry/aliyun/alicloud"
      version = "1.166.0"
    }
  }
}

provider "alicloud" {
  access_key = "xxx"
  secret_key = "xxx"
  region = "cn-shenzhen"
}
EOF

# 清空当前目录下载的provider
[root@node-nfs vpc_terraform]# rm -rf .terraform*

# 重新初始化
[root@node-nfs vpc_terraform]# terraform init

Initializing the backend...

Initializing provider plugins...
- Finding local-registry/aliyun/alicloud versions matching "1.166.0"...
- Installing local-registry/aliyun/alicloud v1.166.0...
- Installed local-registry/aliyun/alicloud v1.166.0 (unauthenticated)

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.

# 查看此时则会在当前项目创建一个本地仓库的软链
[root@node-nfs vpc_terraform]# tree -a
.
├── providers.tf
├── .terraform
│   └── providers
│       └── local-registry
│           └── aliyun
│               └── alicloud
│                   └── 1.166.0
│                       └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/aliyun/alicloud/1.166.0/linux_amd64
└── .terraform.lock.hcl

7 directories, 2 files

博主顺道提前下载下其他Providers

[root@node-nfs vpc_terraform]# cat providers.tf 
terraform {
  required_providers {
    alicloud = {
      #source = "aliyun/alicloud"
      source = "local-registry/aliyun/alicloud"
      version = "1.166.0"
    }
    aws = {
      source = "hashicorp/aws"
      version = "4.13.0"
    }
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.5.0"
    }
    google = {
      source = "hashicorp/google"
      version = "4.20.0"
    }
    kubernetes = {
      source = "hashicorp/kubernetes"
      version = "2.11.0"
    }
  }
}

provider "alicloud" {
  access_key = "xxx"
  secret_key = "xxx"
  region = "cn-shenzhen"
}

[root@node-nfs vpc_terraform]# terraform init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of local-registry/aliyun/alicloud from the dependency lock file
- Finding hashicorp/aws versions matching "4.13.0"...
- Finding hashicorp/azurerm versions matching "3.5.0"...
- Finding hashicorp/google versions matching "4.20.0"...
- Finding hashicorp/kubernetes versions matching "2.11.0"...
- Using previously-installed local-registry/aliyun/alicloud v1.166.0
- Installing hashicorp/aws v4.13.0...
- Installed hashicorp/aws v4.13.0 (signed by HashiCorp)
- Installing hashicorp/azurerm v3.5.0...
- Installed hashicorp/azurerm v3.5.0 (signed by HashiCorp)
- Installing hashicorp/google v4.20.0...
- Installed hashicorp/google v4.20.0 (signed by HashiCorp)
- Installing hashicorp/kubernetes v2.11.0...
- Installed hashicorp/kubernetes v2.11.0 (signed by HashiCorp)

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version 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 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.

移动provider到本地仓库

[root@node-nfs vpc_terraform]# tree -a
.
├── providers.tf
├── .terraform
│   └── providers
│       ├── local-registry
│       │   └── aliyun
│       │       └── alicloud
│       │           └── 1.166.0
│       │               └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/aliyun/alicloud/1.166.0/linux_amd64
│       └── registry.terraform.io
│           └── hashicorp
│               ├── aws
│               │   └── 4.13.0
│               │       └── linux_amd64
│               │           └── terraform-provider-aws_v4.13.0_x5
│               ├── azurerm
│               │   └── 3.5.0
│               │       └── linux_amd64
│               │           └── terraform-provider-azurerm_v3.5.0_x5
│               ├── google
│               │   └── 4.20.0
│               │       └── linux_amd64
│               │           └── terraform-provider-google_v4.20.0_x5
│               └── kubernetes
│                   └── 2.11.0
│                       └── linux_amd64
│                           └── terraform-provider-kubernetes_v2.11.0_x5
└── .terraform.lock.hcl

21 directories, 6 files

[root@node-nfs vpc_terraform]# cp -rp .terraform/providers/registry.terraform.io/* ~/.terraform.d/plugins/local-registry
[root@node-nfs vpc_terraform]# cd ~/.terraform.d/plugins/local-registry
[root@node-nfs local-registry]# pwd
/root/.terraform.d/plugins/local-registry
[root@node-nfs local-registry]# tree -a
.
├── aliyun
│   └── alicloud
│       └── 1.166.0
│           └── linux_amd64
│               └── terraform-provider-alicloud_v1.166.0
└── hashicorp
    ├── aws
    │   └── 4.13.0
    │       └── linux_amd64
    │           └── terraform-provider-aws_v4.13.0_x5
    ├── azurerm
    │   └── 3.5.0
    │       └── linux_amd64
    │           └── terraform-provider-azurerm_v3.5.0_x5
    ├── google
    │   └── 4.20.0
    │       └── linux_amd64
    │           └── terraform-provider-google_v4.20.0_x5
    └── kubernetes
        └── 2.11.0
            └── linux_amd64
                └── terraform-provider-kubernetes_v2.11.0_x5

17 directories, 5 files

最终项目目录文件

[root@node-nfs vpc_terraform]# sed -i 's@hashicorp@local-registry/&@g' providers.tf
[root@node-nfs vpc_terraform]# cat providers.tf 
terraform {
  required_providers {
    alicloud = {
      #source = "aliyun/alicloud"
      source = "local-registry/aliyun/alicloud"
      version = "1.166.0"
    }
    aws = {
      source = "local-registry/hashicorp/aws"
      version = "4.13.0"
    }
    azurerm = {
      source = "local-registry/hashicorp/azurerm"
      version = "3.5.0"
    }
    google = {
      source = "local-registry/hashicorp/google"
      version = "4.20.0"
    }
    kubernetes = {
      source = "local-registry/hashicorp/kubernetes"
      version = "2.11.0"
    }
  }
}

provider "alicloud" {
  access_key = "xxxx"
  secret_key = "xxxx"
  region = "cn-shenzhen"
}

[root@node-nfs vpc_terraform]# terraform init

Initializing the backend...

Initializing provider plugins...
- Finding local-registry/hashicorp/azurerm versions matching "3.5.0"...
- Finding local-registry/hashicorp/google versions matching "4.20.0"...
- Finding local-registry/hashicorp/kubernetes versions matching "2.11.0"...
- Finding local-registry/aliyun/alicloud versions matching "1.166.0"...
- Finding local-registry/hashicorp/aws versions matching "4.13.0"...
- Installing local-registry/hashicorp/azurerm v3.5.0...
- Installed local-registry/hashicorp/azurerm v3.5.0 (unauthenticated)
- Installing local-registry/hashicorp/google v4.20.0...
- Installed local-registry/hashicorp/google v4.20.0 (unauthenticated)
- Installing local-registry/hashicorp/kubernetes v2.11.0...
- Installed local-registry/hashicorp/kubernetes v2.11.0 (unauthenticated)
- Installing local-registry/aliyun/alicloud v1.166.0...
- Installed local-registry/aliyun/alicloud v1.166.0 (unauthenticated)
- Installing local-registry/hashicorp/aws v4.13.0...
- Installed local-registry/hashicorp/aws v4.13.0 (unauthenticated)

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.

[root@node-nfs vpc_terraform]# tree -a
.
├── providers.tf
├── .terraform
│   └── providers
│       └── local-registry
│           ├── aliyun
│           │   └── alicloud
│           │       └── 1.166.0
│           │           └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/aliyun/alicloud/1.166.0/linux_amd64
│           └── hashicorp
│               ├── aws
│               │   └── 4.13.0
│               │       └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/hashicorp/aws/4.13.0/linux_amd64
│               ├── azurerm
│               │   └── 3.5.0
│               │       └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/hashicorp/azurerm/3.5.0/linux_amd64
│               ├── google
│               │   └── 4.20.0
│               │       └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/hashicorp/google/4.20.0/linux_amd64
│               └── kubernetes
│                   └── 2.11.0
│                       └── linux_amd64 -> /root/.terraform.d/plugins/local-registry/hashicorp/kubernetes/2.11.0/linux_amd64
└── .terraform.lock.hcl

20 directories, 2 files

Terraform简单实例

创建一个vpc/vswitch/sercuritgroup

[root@node-nfs vpc_terraform]# cat >providers.tf<<'EOF'
terraform {
  required_providers {
    alicloud = {
      #source = "aliyun/alicloud"
      source = "local-registry/aliyun/alicloud"
      version = "1.166.0"
    }
    aws = {
      source = "local-registry/hashicorp/aws"
      version = "4.13.0"
    }
    azurerm = {
      source = "local-registry/hashicorp/azurerm"
      version = "3.5.0"
    }
    google = {
      source = "local-registry/hashicorp/google"
      version = "4.20.0"
    }
    kubernetes = {
      source = "local-registry/hashicorp/kubernetes"
      version = "2.11.0"
    }
  }
}
EOF

[root@node-nfs vpc_terraform]# cat >terraform.tf<<'EOF'
provider "alicloud" {
  access_key = "xxx"
  secret_key = "xxx"
  region = "cn-guangzhou"
}
resource "alicloud_vpc" "main" {
  # VPC名称
  vpc_name = "terraform-vpc"
  # VPC地址块
  cidr_block = "10.1.0.0/21"
}

resource "alicloud_vswitch" "main" {
  # VPC ID
  vpc_id            = alicloud_vpc.main.id
  # 交换机地址块
  cidr_block        = "10.1.0.0/24"
  # 可用区
  availability_zone = "cn-guangzhou-a"
  # 资源依赖,会优先创建该依赖资源
  depends_on = [alicloud_vpc.main]
}

resource "alicloud_security_group" "default" {
  name = "default"
  vpc_id = alicloud_vpc.main.id
}

resource "alicloud_security_group_rule" "allow_all_tcp" {
  type              = "ingress"
  ip_protocol       = "tcp"
  nic_type          = "intranet"
  policy            = "accept"
  port_range        = "1/65535"
  priority          = 1
  security_group_id = alicloud_security_group.default.id
  cidr_ip           = "0.0.0.0/0"
}
EOF

测试计划

[root@node-nfs vpc_terraform]# terraform plan

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:

  # alicloud_security_group.default will be created
  + resource "alicloud_security_group" "default" {
      + id                  = (known after apply)
      + inner_access        = (known after apply)
      + inner_access_policy = (known after apply)
      + name                = "default"
      + security_group_type = "normal"
      + vpc_id              = (known after apply)
    }

  # alicloud_security_group_rule.allow_all_tcp will be created
  + resource "alicloud_security_group_rule" "allow_all_tcp" {
      + cidr_ip           = "0.0.0.0/0"
      + id                = (known after apply)
      + ip_protocol       = "tcp"
      + nic_type          = "intranet"
      + policy            = "accept"
      + port_range        = "1/65535"
      + prefix_list_id    = (known after apply)
      + priority          = 1
      + security_group_id = (known after apply)
      + type              = "ingress"
    }

  # alicloud_vpc.main will be created
  + resource "alicloud_vpc" "main" {
      + cidr_block        = "10.1.0.0/21"
      + id                = (known after apply)
      + ipv6_cidr_block   = (known after apply)
      + name              = (known after apply)
      + resource_group_id = (known after apply)
      + route_table_id    = (known after apply)
      + router_id         = (known after apply)
      + router_table_id   = (known after apply)
      + status            = (known after apply)
      + vpc_name          = "terraform-vpc"
    }

  # alicloud_vswitch.main will be created
  + resource "alicloud_vswitch" "main" {
      + availability_zone = "cn-guangzhou-a"
      + cidr_block        = "10.1.0.0/24"
      + id                = (known after apply)
      + name              = (known after apply)
      + status            = (known after apply)
      + vpc_id            = (known after apply)
      + vswitch_name      = (known after apply)
      + zone_id           = (known after apply)
    }

Plan: 4 to add, 0 to change, 0 to destroy.
╷
│ Warning: "availability_zone": [DEPRECATED] Field 'availability_zone' has been deprecated from provider version 1.119.0. New field 'zone_id' instead.
│ 
│   with alicloud_vswitch.main,
│   on terraform.tf line 13, in resource "alicloud_vswitch" "main":
│   13: resource "alicloud_vswitch" "main" {
│ 
│ (and one more similar warning elsewhere)
╵

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

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.

开始创建资源

[root@node-nfs vpc_terraform]# terraform apply

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:

  # alicloud_security_group.default will be created
  + resource "alicloud_security_group" "default" {
      + id                  = (known after apply)
      + inner_access        = (known after apply)
      + inner_access_policy = (known after apply)
      + name                = "default"
      + security_group_type = "normal"
      + vpc_id              = (known after apply)
    }

  # alicloud_security_group_rule.allow_all_tcp will be created
  + resource "alicloud_security_group_rule" "allow_all_tcp" {
      + cidr_ip           = "0.0.0.0/0"
      + id                = (known after apply)
      + ip_protocol       = "tcp"
      + nic_type          = "intranet"
      + policy            = "accept"
      + port_range        = "1/65535"
      + prefix_list_id    = (known after apply)
      + priority          = 1
      + security_group_id = (known after apply)
      + type              = "ingress"
    }

  # alicloud_vpc.main will be created
  + resource "alicloud_vpc" "main" {
      + cidr_block        = "10.1.0.0/21"
      + id                = (known after apply)
      + ipv6_cidr_block   = (known after apply)
      + name              = (known after apply)
      + resource_group_id = (known after apply)
      + route_table_id    = (known after apply)
      + router_id         = (known after apply)
      + router_table_id   = (known after apply)
      + status            = (known after apply)
      + vpc_name          = "terraform-vpc"
    }

  # alicloud_vswitch.main will be created
  + resource "alicloud_vswitch" "main" {
      + availability_zone = "cn-guangzhou-a"
      + cidr_block        = "10.1.0.0/24"
      + id                = (known after apply)
      + name              = (known after apply)
      + status            = (known after apply)
      + vpc_id            = (known after apply)
      + vswitch_name      = (known after apply)
      + zone_id           = (known after apply)
    }

Plan: 4 to add, 0 to change, 0 to destroy.
╷
│ Warning: "availability_zone": [DEPRECATED] Field 'availability_zone' has been deprecated from provider version 1.119.0. New field 'zone_id' instead.
│ 
│   with alicloud_vswitch.main,
│   on terraform.tf line 13, in resource "alicloud_vswitch" "main":
│   13: resource "alicloud_vswitch" "main" {
│ 
│ (and one more similar warning elsewhere)
╵

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_vpc.main: Creating...
alicloud_vpc.main: Creation complete after 6s [id=vpc-7xvidwo6rkas2uwxf0274]
alicloud_vswitch.main: Creating...
alicloud_security_group.default: Creating...
alicloud_security_group.default: Creation complete after 1s [id=sg-7xv2mzcim9shk3xtf2gt]
alicloud_security_group_rule.allow_all_tcp: Creating...
alicloud_security_group_rule.allow_all_tcp: Creation complete after 0s [id=sg-7xv2mzcim9shk3xtf2gt:ingress:tcp:1/65535:intranet:0.0.0.0/0:accept:1]
alicloud_vswitch.main: Creation complete after 5s [id=vsw-7xvjdga6r3nvut6w2qith]
╷
│ Warning: "availability_zone": [DEPRECATED] Field 'availability_zone' has been deprecated from provider version 1.119.0. New field 'zone_id' instead.
│ 
│   with alicloud_vswitch.main,
│   on terraform.tf line 13, in resource "alicloud_vswitch" "main":
│   13: resource "alicloud_vswitch" "main" {
│ 
╵

Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

查看资源状态

[root@node-nfs vpc_terraform]# terraform show
# alicloud_security_group.default:
resource "alicloud_security_group" "default" {
    id                  = "sg-7xv2mzcim9shk3xtf2gt"
    inner_access        = true
    inner_access_policy = "Accept"
    name                = "default"
    security_group_type = "normal"
    vpc_id              = "vpc-7xvidwo6rkas2uwxf0274"
}

# alicloud_security_group_rule.allow_all_tcp:
resource "alicloud_security_group_rule" "allow_all_tcp" {
    cidr_ip           = "0.0.0.0/0"
    id                = "sg-7xv2mzcim9shk3xtf2gt:ingress:tcp:1/65535:intranet:0.0.0.0/0:accept:1"
    ip_protocol       = "tcp"
    nic_type          = "intranet"
    policy            = "accept"
    port_range        = "1/65535"
    priority          = 1
    security_group_id = "sg-7xv2mzcim9shk3xtf2gt"
    type              = "ingress"
}

# alicloud_vpc.main:
resource "alicloud_vpc" "main" {
    cidr_block        = "10.1.0.0/21"
    id                = "vpc-7xvidwo6rkas2uwxf0274"
    name              = "terraform-vpc"
    resource_group_id = "rg-acfmzzrafyp2giq"
    route_table_id    = "vtb-7xvsfkzks8u79j0xskj6q"
    router_id         = "vrt-7xv01fysjtfmybbfqyq01"
    router_table_id   = "vtb-7xvsfkzks8u79j0xskj6q"
    status            = "Available"
    vpc_name          = "terraform-vpc"
}

# alicloud_vswitch.main:
resource "alicloud_vswitch" "main" {
    availability_zone = "cn-guangzhou-a"
    cidr_block        = "10.1.0.0/24"
    id                = "vsw-7xvjdga6r3nvut6w2qith"
    status            = "Available"
    vpc_id            = "vpc-7xvidwo6rkas2uwxf0274"
    zone_id           = "cn-guangzhou-a"
}

删除资源

[root@node-nfs vpc_terraform]# terraform destroy
alicloud_vpc.main: Refreshing state... [id=vpc-7xvidwo6rkas2uwxf0274]
alicloud_vswitch.main: Refreshing state... [id=vsw-7xvjdga6r3nvut6w2qith]
alicloud_security_group.default: Refreshing state... [id=sg-7xv2mzcim9shk3xtf2gt]
alicloud_security_group_rule.allow_all_tcp: Refreshing state... [id=sg-7xv2mzcim9shk3xtf2gt:ingress:tcp:1/65535:intranet:0.0.0.0/0:accept:1]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # alicloud_security_group.default will be destroyed
  - resource "alicloud_security_group" "default" {
      - id                  = "sg-7xv2mzcim9shk3xtf2gt" -> null
      - inner_access        = true -> null
      - inner_access_policy = "Accept" -> null
      - name                = "default" -> null
      - security_group_type = "normal" -> null
      - tags                = {} -> null
      - vpc_id              = "vpc-7xvidwo6rkas2uwxf0274" -> null
    }

  # alicloud_security_group_rule.allow_all_tcp will be destroyed
  - resource "alicloud_security_group_rule" "allow_all_tcp" {
      - cidr_ip           = "0.0.0.0/0" -> null
      - id                = "sg-7xv2mzcim9shk3xtf2gt:ingress:tcp:1/65535:intranet:0.0.0.0/0:accept:1" -> null
      - ip_protocol       = "tcp" -> null
      - nic_type          = "intranet" -> null
      - policy            = "accept" -> null
      - port_range        = "1/65535" -> null
      - priority          = 1 -> null
      - security_group_id = "sg-7xv2mzcim9shk3xtf2gt" -> null
      - type              = "ingress" -> null
    }

  # alicloud_vpc.main will be destroyed
  - resource "alicloud_vpc" "main" {
      - cidr_block            = "10.1.0.0/21" -> null
      - id                    = "vpc-7xvidwo6rkas2uwxf0274" -> null
      - name                  = "terraform-vpc" -> null
      - resource_group_id     = "rg-acfmzzrafyp2giq" -> null
      - route_table_id        = "vtb-7xvsfkzks8u79j0xskj6q" -> null
      - router_id             = "vrt-7xv01fysjtfmybbfqyq01" -> null
      - router_table_id       = "vtb-7xvsfkzks8u79j0xskj6q" -> null
      - secondary_cidr_blocks = [] -> null
      - status                = "Available" -> null
      - user_cidrs            = [] -> null
      - vpc_name              = "terraform-vpc" -> null
    }

  # alicloud_vswitch.main will be destroyed
  - resource "alicloud_vswitch" "main" {
      - availability_zone = "cn-guangzhou-a" -> null
      - cidr_block        = "10.1.0.0/24" -> null
      - id                = "vsw-7xvjdga6r3nvut6w2qith" -> null
      - status            = "Available" -> null
      - tags              = {} -> null
      - vpc_id            = "vpc-7xvidwo6rkas2uwxf0274" -> null
      - zone_id           = "cn-guangzhou-a" -> null
    }

Plan: 0 to add, 0 to change, 4 to destroy.
╷
│ Warning: "availability_zone": [DEPRECATED] Field 'availability_zone' has been deprecated from provider version 1.119.0. New field 'zone_id' instead.
│ 
│   with alicloud_vswitch.main,
│   on terraform.tf line 13, in resource "alicloud_vswitch" "main":
│   13: resource "alicloud_vswitch" "main" {
│ 
╵

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: yes

alicloud_vswitch.main: Destroying... [id=vsw-7xvjdga6r3nvut6w2qith]
alicloud_security_group_rule.allow_all_tcp: Destroying... [id=sg-7xv2mzcim9shk3xtf2gt:ingress:tcp:1/65535:intranet:0.0.0.0/0:accept:1]
alicloud_security_group_rule.allow_all_tcp: Destruction complete after 1s
alicloud_security_group.default: Destroying... [id=sg-7xv2mzcim9shk3xtf2gt]
alicloud_security_group.default: Destruction complete after 0s
alicloud_vswitch.main: Destruction complete after 6s
alicloud_vpc.main: Destroying... [id=vpc-7xvidwo6rkas2uwxf0274]
alicloud_vpc.main: Destruction complete after 5s

Destroy complete! Resources: 4 destroyed.

正文完
 587
xadocker
版权声明:本站原创文章,由 xadocker 2022-04-02发表,共计21059字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(一条评论)
骆驼 评论达人 LV.1
2022-10-11 10:46:06 回复

可以,目前再看一些iac的文章

 Windows  Chrome  中国广东省佛山市联通