본문 바로가기

퍼블릭 클라우드

테라폼 vpc peering import(terraform import)

반응형

테라폼 vpc peering import(terraform import)

vpc peering connection import

[버지니아 리전]

vpc resources 파일 생성

vim peering.tf
#####VPC 페어링
resource "aws_vpc_peering_connection" "vatosg" {}
terraform import aws_vpc_peering_connection.vatosg pcx-03c5b
$ terraform import aws_vpc_peering_connection.vatosg pcx-03c5b
aws_vpc_peering_connection.vatosg: Importing from ID "pcx-03c5b"...
aws_vpc_peering_connection.vatosg: Import prepared!
  Prepared aws_vpc_peering_connection for import
aws_vpc_peering_connection.vatosg: Refreshing state... [id=pcx-03c5b]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

vpc peering connection accepter import

[버지니아 리전]

vpc resources 파일 생성

vim peering.tf
#####VPC 페어링
resource "aws_vpc_peering_connection_accepter" "vatosg" {}
terraform import aws_vpc_peering_connection_accepter.vatosg pcx-03c5b
$ terraform import aws_vpc_peering_connection_accepter.vatosg pcx-03c5b
aws_vpc_peering_connection_accepter.vatosg: Importing from ID "pcx-03c5b"...
aws_vpc_peering_connection_accepter.vatosg: Import prepared!
  Prepared aws_vpc_peering_connection_accepter for import
aws_vpc_peering_connection_accepter.vatosg: Refreshing state... [id=pcx-03c5b]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
terraform show

import한 내용을 기반으로 vpc 모듈 편집

vim vpcpeering.tf
$ vim vpcpeering.tf
resource "aws_vpc_peering_connection" "vatosg" {
    #accept_status = "active"
    #id            = "pcx-03c5b"
    vpc_id        = "vpc-02e17"
    peer_owner_id = "57243"
    peer_region   = "ap-southeast-1"
    peer_vpc_id   = "vpc-0bbe2"
    lifecycle {
        ignore_changes = [ tags.CreatedDate ]
    }
    tags = {
        Name = "vatosg"
        Environment = "env-prod"
        CreateUser = "terraform"
        Owner = "sangchul"
        Project = "aaa"
        Role = "vpcpeering"
        Service = "network"
        CreatedDate = timestamp()
    }
    accepter {
        allow_classic_link_to_remote_vpc = false
        allow_remote_vpc_dns_resolution  = false
        allow_vpc_to_remote_classic_link = false
    }
    requester {
        allow_classic_link_to_remote_vpc = false
        allow_remote_vpc_dns_resolution  = false
        allow_vpc_to_remote_classic_link = false
    }
    timeouts {}
}

resource "aws_vpc_peering_connection_accepter" "vatosg" {
    vpc_peering_connection_id = "pcx-03c5b"
    accepter {
        allow_classic_link_to_remote_vpc = false
        allow_remote_vpc_dns_resolution  = false
        allow_vpc_to_remote_classic_link = false
    }
    requester {
        allow_classic_link_to_remote_vpc = false
        allow_remote_vpc_dns_resolution  = false
        allow_vpc_to_remote_classic_link = false
    }
    lifecycle {
        ignore_changes = [ tags.CreatedDate ]
    }
    tags = {
        Name = "vatosg"
        Environment = "env-prod"
        CreateUser = "terraform"
        Owner = "sangchul"
        Project = "aaa"
        Role = "vpcpeering"
        Service = "network"
        CreatedDate = timestamp()
    }
}

 

728x90
반응형