당신이 remote state backend를 사용하는 가정, 당신은 remote state data source로 OPS 네트워크 스택을 끌어하고 당신이 원하는 어느 덧 스택에서의 라우팅 테이블을 변경할 수 있습니다 에 연결할 수 있습니다.
시도하고 (보일러 플레이트의 많은 실종 명백하게) 최소한의 예를 수행합니다
# my_ops_stack.tf
provider "aws" {
region = "eu-west-1"
}
module "ops_stack" {
source = "/my/modules/ops_stack"
cidr = "10.1.0.0/16"
// other vars probably
}
// the outputs which will be accessible
// via the remote state data source:
output "routing_table_id" {
value = "${module.ops_stack.routing_table_id}"
}
output "vpc_id" {
value = "${module.ops_stack.vpc_id}"
}
output "vpc_cidr" {
value = "10.1.0.0/16"
}
을 거 야 지금 configure terraform의 CLI (this will soon be possible in config)를 사용하여이 스택에 대한 원격 상태 백엔드 :
# Run in the same folder as my_ops_stack.tf
terraform remote config \
-backend=s3 \
-backend-config="bucket=my-state-bucket" \
-backend-config="key=ops-stack/terraform.tfstate" \
-backend-config="region=eu-west-1"
을
terraform apply
# the usual stuff... but now synced with s3!
: 당신은 스택에 적용
지금 상태 백엔드 구성, 변경 사항은 백엔드에 동기화됩니다 이제
, 새 임시 스택의 템플릿 (dev에, 자극, 품질 보증, STG, UAT 등 CTE) :
당신이 임시 스택이 완료되면
# my_dev_stack.tf
provider "aws" {
region = "eu-west-1"
}
// Pull in your ops stack from the remote backend:
data "terraform_remote_state" "ops_stack" {
backend = "s3"
config {
bucket = "my-state-bucket"
key = "ops-stack/terraform.tfstate"
region = "eu-west-1"
}
}
// Create your dev stack
module "dev_stack" {
source = "/my/modules/dev_stack"
cidr = "10.2.0.0/16"
// The ops_stack vpc id for creating the peering connection:
ops_vpc_id = "${data.terraform_remote_state.ops_stack.vpc_id}"
// Maybe some security group rules you wanna setup
allow_access_from = "${data.terraform_remote_state.ops_stack.vpc_cidr}"
// other vars probably
}
// And use its outputs to add a route to the
// ops vpc routing table from the dev stack!
resource "aws_route" "ops_to_dev" {
route_table_id = "${data.terraform_remote_state.ops_stack.routing_table_id}"
destination_cidr_block = "10.2.0.0/16" // dev_stack's cidr
vpc_peering_connection_id = "${module.dev_stack.vpcx_id}"
}
, 안전하게 파괴 할 수있다 그것도 ops 스택에서 그 경로를 정리할 것입니다.
희망은 다음과 같습니다.