0

AWS コンソールから手動で作成された AWS clientVPN があり、約 20 プラスのルート テーブル エントリがあります。ここで、これをテラフォーミングして、テラフォーミングを使用して新しいルートを追加できるようにします。

Terraform インポートを使用して ClientVPN 情報をインポートしました。既存のすべてのルートをインポートするには、一度に 1 つのルートをインポートすることもできます。ルートごとにインポートすることもできます。以下に示すように、main.tf にリソース エントリを追加する必要があります。

Command used to import the route table entry:
$ terraform import aws_ec2_client_vpn_route.example cvpn-endpoint-0e3e121d2,subnet-08acf2,<CIDR>
This command updates the .tfstate file and when I run terraform plan it gives me an error because I need to add resource section for this in main.tf file. 

resource "aws_ec2_client_vpn_route" "example" {
  client_vpn_endpoint_id = var.client_vpn_endpoint_id
  destination_cidr_block = "CIDR"
  target_vpc_subnet_id   = var.target_vpc_subnet_id
}

resource "aws_ec2_client_vpn_route" "example1" {
  client_vpn_endpoint_id = var.client_vpn_endpoint_id
  destination_cidr_block = "CIDR"
  target_vpc_subnet_id   = var.target_vpc_subnet_id
}

ルートをインポートするたびに、main.tf にリソースを追加する必要があります。20 個のルート テーブル エントリがある場合、main.tf ファイルに 20 個のリソース エントリを書き込む必要がありますか?

main.tf で 1 つのリソース エントリを使用したいだけですが、どうすれば可能ですか?

インポート後、terraform プランを実行したときに、出力を確認します。

% terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

aws_ec2_client_vpn_route.example: Refreshing state... [id=cvpn-endpoint,subnet-02231,0.0.0.0/16]
aws_ec2_client_vpn_endpoint.example: Refreshing state... [id=cvpn-endpoint]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  - destroy

Terraform will perform the following actions:

  # aws_ec2_client_vpn_route.example will be destroyed
  - resource "aws_ec2_client_vpn_route" "example" {
      - client_vpn_endpoint_id = "cvpn-endpoint" -> null
      - description            = "Default Route" -> null
      - destination_cidr_block = "0.0.0.0/16" -> null
      - id                     = "cvpn-endpoint,subnet-02231308,0.0.0.0/16" -> null
      - origin                 = "associate" -> null
      - target_vpc_subnet_id   = "subnet-022313" -> null
      - type                   = "Nat" -> null
    }

  # aws_ec2_client_vpn_route.example["Default Route"] will be created
  + resource "aws_ec2_client_vpn_route" "example" {
      + client_vpn_endpoint_id = "cvpn-endpoint"
      + description            = "Default Route"
      + destination_cidr_block = "0.0.0.0/16"
      + id                     = (known after apply)
      + origin                 = (known after apply)
      + target_vpc_subnet_id   = "subnet-022313"
      + type                   = (known after apply)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

リソース名が一致していないため、破棄して再度作成しています。しかし、テラフォーム適用を行うと、最初にリソースを作成し、同じ CIDR のために失敗するため失敗します。

4

1 に答える 1