为啥 terraform 试图重建已经提供的基础设施?
Posted
技术标签:
【中文标题】为啥 terraform 试图重建已经提供的基础设施?【英文标题】:Why terraform is trying to recreate infrastructures which is already provision?为什么 terraform 试图重建已经提供的基础设施? 【发布时间】:2021-08-09 00:14:09 【问题描述】:当我第一次使用 jenkins 计划运行基础架构创建时,即创建所有基础架构,例如 EC2、EBS、RDS 和 EFS。我在 s3 和 dynamoDB 中维护我的 tf 状态文件。 如下。
terraform init -plugin-dir=$tf_plugin_dir \
-backend-config="bucket=$s3_bucket" \
-backend-config="key=$Purpose/$deploy_env/tfstate" \
-backend-config="region=$aws_region" \
-backend-config="dynamodb_table=$dynamodb_table" \
但是当我重新运行计划时,据我所知,如果没有改变,它不应该改变,但请注意它正在改变基础设施,如下所示。
terraform plan -var-file="../../../../configurations/$account_prop_path/surv.tfvars" -var RelVersion="$RelVersion" -var Purpose="$Purpose" -var ami_id="$ami_id" -var ora_rds_snap_id="$ora_rds_snap_id"
也得到以下错误。
错误:更新 EFS 文件系统“fs-065db0f6”时出错:BadRequest: 文件系统不会更新。请求的吞吐量模式或 提供的吞吐量值与当前模式相同,并且 价值。 响应元数据: 状态码:400, RequestID: "b57a53bb-5a65-4bdc-b748-b441c7ad3d19" , ErrorCode: "BadRequest", Message_: "文件系统不会 更新。请求的吞吐量模式或预配的吞吐量值 与当前模式和值相同。”
Terraform Plan 输出如下
# module.efs-cluster.aws_efs_file_system.efs will be updated in-place
~ resource "aws_efs_file_system" "efs"
arn = "arn:aws:elasticfilesystem:eu-west-2:946581213364:file-system/fs-065db0f6"
creation_token = "terraform-20210519172018074600000001"
dns_name = "fs-065db0f6.efs.eu-west-2.amazonaws.com"
encrypted = true
id = "fs-065db0f6"
kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d"
performance_mode = "generalPurpose"
~ provisioned_throughput_in_mibps = 0 -> 350
tags =
"AWSResoureceType" = "EFS"
"Account" = "MITSURV"
"ApplicationID" = "APP-00682"
"ApplicationName" = "MITCAPMARKET"
"Automation" = "PLACEHOLDER"
"BusinessEntitiy" = "MIT"
"CostCentre" = "CC55219"
"DBVersion" = "N/A"
"DataClassification" = "3"
"Division" = "DEVOPS"
"Environment" = "NONPROD"
"Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-EFS"
"OSVersion" = "N/A"
"Project" = "SURV"
"ProjectCode" = "25127-100"
"Purpose" = "QA1"
"RelVersion" = "N/A"
"ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-EFS"
"VersionNumber" = "N/A"
"Workload" = "TEST"
throughput_mode = "bursting"
# module.mn-ec2.aws_instance.this[0] must be replaced
-/+ resource "aws_instance" "this"
ami = "ami-0e6de0d71c64a2b5b"
~ arn = "arn:aws:ec2:eu-west-2:946581213364:instance/i-0dbe05f55f05d9a4c" -> (known after apply)
~ associate_public_ip_address = false -> (known after apply)
~ availability_zone = "eu-west-2a" -> (known after apply)
~ cpu_core_count = 8 -> (known after apply)
~ cpu_threads_per_core = 2 -> (known after apply)
disable_api_termination = false
ebs_optimized = false
get_password_data = false
- hibernation = false -> null
+ host_id = (known after apply)
iam_instance_profile = "mit-surv-nonprod-service-role"
~ id = "i-0dbe05f55f05d9a4c" -> (known after apply)
~ instance_state = "running" -> (known after apply)
instance_type = "r5.4xlarge"
~ ipv6_address_count = 0 -> (known after apply)
~ ipv6_addresses = [] -> (known after apply)
key_name = "mit-surv-nonprod-london"
monitoring = false
+ outpost_arn = (known after apply)
+ password_data = (known after apply)
+ placement_group = (known after apply)
~ primary_network_interface_id = "eni-061ea31bfbb5e93f6" -> (known after apply)
~ private_dns = "ip-10-142-175-43.eu-west-2.compute.internal" -> (known after apply)
~ private_ip = "10.142.175.43" -> (known after apply)
+ public_dns = (known after apply)
+ public_ip = (known after apply)
~ secondary_private_ips = [] -> (known after apply)
~ security_groups = [] -> (known after apply)
source_dest_check = true
subnet_id = "subnet-0fc6bd95884e9796a"
~ tags =
"AWSResoureceType" = "EC2"
"Account" = "MITSURV"
"ApplicationID" = "APP-00682"
"ApplicationName" = "MITCAPMARKET"
"Automation" = "PLACEHOLDER"
~ "BaseImageName" = "redhat_linux_cis_7.X__62__1604538021" -> "Add_Your_Base_AMI_Name"
"BusinessEntitiy" = "MIT"
"CostCentre" = "CC55219"
"DBVersion" = "N/A"
"DataClassification" = "3"
"Division" = "DEVOPS"
"Environment" = "NONPROD"
"Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EC2"
"OSVersion" = "N/A"
"Project" = "SURV"
"ProjectCode" = "25127-100"
"Purpose" = "QA1"
"RelVersion" = "4.0.0.0.i2"
"ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EC2"
"VersionNumber" = "N/A"
"Workload" = "TEST"
- "mitcct_ec2_ami-id" = "ami-0e6de0d71c64a2b5b" -> null
- "mitcct_ec2_instance-id" = "i-0dbe05f55f05d9a4c" -> null
- "mitcct_ec2_instance-type" = "r5.4xlarge" -> null
- "mitcct_ec2_local-hostname" = "ip-10-142-175-43.946581213364.ew2.aws.dev.r53." -> null
- "mitcct_ec2_local-ipv4" = "10.142.175.43" -> null
- "mitcct_ec2_subnet-id" = "subnet-0fc6bd95884e9796a" -> null
- "mitcct_ec2_vpc-id" = "vpc-0b7dd5e37cb613bfa" -> null
- "mitcct_iam_InstanceProfileArn" = "arn:aws:iam::946581213364:instance-profile/mit-surv-nonprod-service-role" -> null
- "mitcct_iam_role" = "mit-surv-nonprod-service-role" -> null
"node_type" = "master"
tenancy = "default"
user_data = "cbca7c32e2ea4dbc3ae3777d3738ca8cbc7218b3"
vpc_security_group_ids = [
"sg-00298692f55f253e5",
]
credit_specification
- ebs_block_device # forces replacement
- delete_on_termination = true -> null
- device_name = "/dev/sdb" -> null
- encrypted = true -> null
- iops = 300 -> null
- kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d" -> null
- snapshot_id = "snap-0afd755a1f452c2fe" -> null
- tags =
- "AWSResoureceType" = "EC2"
- "Account" = "MITSURV"
- "ApplicationID" = "APP-00682"
- "ApplicationName" = "MITCAPMARKET"
- "Automation" = "PLACEHOLDER"
- "BaseImageName" = "Add_Your_Base_AMI_Name"
- "BusinessEntitiy" = "MIT"
- "CostCentre" = "CC55219"
- "DBVersion" = "N/A"
- "DataClassification" = "3"
- "Division" = "DEVOPS"
- "Environment" = "NONPROD"
- "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "OSVersion" = "N/A"
- "Project" = "SURV"
- "ProjectCode" = "25127-100"
- "Purpose" = "QA1"
- "RelVersion" = "4.0.0.0.i2"
- "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "VersionNumber" = "N/A"
- "Workload" = "TEST"
- "mount" = "/x01"
- "node_type" = "master"
-> null
- throughput = 0 -> null
- volume_id = "vol-036859ecaf1def640" -> null
- volume_size = 100 -> null
- volume_type = "gp2" -> null
+ ebs_block_device # forces replacement
+ delete_on_termination = true
+ device_name = "/dev/sdb"
+ encrypted = true
+ iops = (known after apply)
+ kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d"
+ snapshot_id = (known after apply)
+ tags =
+ "AWSResoureceType" = "EC2"
+ "Account" = "MITSURV"
+ "ApplicationID" = "APP-00682"
+ "ApplicationName" = "MITCAPMARKET"
+ "Automation" = "PLACEHOLDER"
+ "BaseImageName" = "Add_Your_Base_AMI_Name"
+ "BusinessEntitiy" = "MIT"
+ "CostCentre" = "CC55219"
+ "DBVersion" = "N/A"
+ "DataClassification" = "3"
+ "Division" = "DEVOPS"
+ "Environment" = "NONPROD"
+ "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "OSVersion" = "N/A"
+ "Project" = "SURV"
+ "ProjectCode" = "25127-100"
+ "Purpose" = "QA1"
+ "RelVersion" = "4.0.0.0.i2"
+ "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "VersionNumber" = "N/A"
+ "Workload" = "TEST"
+ "mount" = "/x01"
+ "node_type" = "master"
+ throughput = (known after apply)
+ volume_id = (known after apply)
+ volume_size = 100
+ volume_type = "gp2"
- ebs_block_device # forces replacement
- delete_on_termination = true -> null
- device_name = "/dev/sdc" -> null
- encrypted = true -> null
- iops = 1500 -> null
- kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d" -> null
- tags =
- "AWSResoureceType" = "EC2"
- "Account" = "MITSURV"
- "ApplicationID" = "APP-00682"
- "ApplicationName" = "MITCAPMARKET"
- "Automation" = "PLACEHOLDER"
- "BaseImageName" = "Add_Your_Base_AMI_Name"
- "BusinessEntitiy" = "MIT"
- "CostCentre" = "CC55219"
- "DBVersion" = "N/A"
- "DataClassification" = "3"
- "Division" = "DEVOPS"
- "Environment" = "NONPROD"
- "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "OSVersion" = "N/A"
- "Project" = "SURV"
- "ProjectCode" = "25127-100"
- "Purpose" = "QA1"
- "RelVersion" = "4.0.0.0.i2"
- "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "VersionNumber" = "N/A"
- "Workload" = "TEST"
- "mount" = "/x02"
- "node_type" = "master"
-> null
- throughput = 0 -> null
- volume_id = "vol-0a085bfad9f6cce82" -> null
- volume_size = 500 -> null
- volume_type = "gp2" -> null
+ ebs_block_device # forces replacement
+ delete_on_termination = true
+ device_name = "/dev/sdc"
+ encrypted = true
+ iops = (known after apply)
+ kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d"
+ snapshot_id = (known after apply)
+ tags =
+ "AWSResoureceType" = "EC2"
+ "Account" = "MITSURV"
+ "ApplicationID" = "APP-00682"
+ "ApplicationName" = "MITCAPMARKET"
+ "Automation" = "PLACEHOLDER"
+ "BaseImageName" = "Add_Your_Base_AMI_Name"
+ "BusinessEntitiy" = "MIT"
+ "CostCentre" = "CC55219"
+ "DBVersion" = "N/A"
+ "DataClassification" = "3"
+ "Division" = "DEVOPS"
+ "Environment" = "NONPROD"
+ "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "OSVersion" = "N/A"
+ "Project" = "SURV"
+ "ProjectCode" = "25127-100"
+ "Purpose" = "QA1"
+ "RelVersion" = "4.0.0.0.i2"
+ "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "VersionNumber" = "N/A"
+ "Workload" = "TEST"
+ "mount" = "/x02"
+ "node_type" = "master"
+ throughput = (known after apply)
+ volume_id = (known after apply)
+ volume_size = 500
+ volume_type = "gp2"
- ebs_block_device # forces replacement
- delete_on_termination = true -> null
- device_name = "/dev/sdd" -> null
- encrypted = true -> null
- iops = 3000 -> null
- kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d" -> null
- tags =
- "AWSResoureceType" = "EC2"
- "Account" = "MITSURV"
- "ApplicationID" = "APP-00682"
- "ApplicationName" = "MITCAPMARKET"
- "Automation" = "PLACEHOLDER"
- "BaseImageName" = "Add_Your_Base_AMI_Name"
- "BusinessEntitiy" = "MIT"
- "CostCentre" = "CC55219"
- "DBVersion" = "N/A"
- "DataClassification" = "3"
- "Division" = "DEVOPS"
- "Environment" = "NONPROD"
- "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "OSVersion" = "N/A"
- "Project" = "SURV"
- "ProjectCode" = "25127-100"
- "Purpose" = "QA1"
- "RelVersion" = "4.0.0.0.i2"
- "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "VersionNumber" = "N/A"
- "Workload" = "TEST"
- "mount" = "/x03"
- "node_type" = "master"
-> null
- throughput = 0 -> null
- volume_id = "vol-07212e8813372626d" -> null
- volume_size = 1000 -> null
- volume_type = "gp2" -> null
+ ebs_block_device # forces replacement
+ delete_on_termination = true
+ device_name = "/dev/sdd"
+ encrypted = true
+ iops = (known after apply)
+ kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d"
+ snapshot_id = (known after apply)
+ tags =
+ "AWSResoureceType" = "EC2"
+ "Account" = "MITSURV"
+ "ApplicationID" = "APP-00682"
+ "ApplicationName" = "MITCAPMARKET"
+ "Automation" = "PLACEHOLDER"
+ "BaseImageName" = "Add_Your_Base_AMI_Name"
+ "BusinessEntitiy" = "MIT"
+ "CostCentre" = "CC55219"
+ "DBVersion" = "N/A"
+ "DataClassification" = "3"
+ "Division" = "DEVOPS"
+ "Environment" = "NONPROD"
+ "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "OSVersion" = "N/A"
+ "Project" = "SURV"
+ "ProjectCode" = "25127-100"
+ "Purpose" = "QA1"
+ "RelVersion" = "4.0.0.0.i2"
+ "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "VersionNumber" = "N/A"
+ "Workload" = "TEST"
+ "mount" = "/x03"
+ "node_type" = "master"
+ throughput = (known after apply)
+ volume_id = (known after apply)
+ volume_size = 1000
+ volume_type = "gp2"
- ebs_block_device # forces replacement
- delete_on_termination = true -> null
- device_name = "/dev/sde" -> null
- encrypted = true -> null
- iops = 15000 -> null
- kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d" -> null
- tags =
- "AWSResoureceType" = "EC2"
- "Account" = "MITSURV"
- "ApplicationID" = "APP-00682"
- "ApplicationName" = "MITCAPMARKET"
- "Automation" = "PLACEHOLDER"
- "BaseImageName" = "Add_Your_Base_AMI_Name"
- "BusinessEntitiy" = "MIT"
- "CostCentre" = "CC55219"
- "DBVersion" = "N/A"
- "DataClassification" = "3"
- "Division" = "DEVOPS"
- "Environment" = "NONPROD"
- "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "OSVersion" = "N/A"
- "Project" = "SURV"
- "ProjectCode" = "25127-100"
- "Purpose" = "QA1"
- "RelVersion" = "4.0.0.0.i2"
- "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
- "VersionNumber" = "N/A"
- "Workload" = "TEST"
- "mount" = "/x04"
- "node_type" = "master"
-> null
- throughput = 0 -> null
- volume_id = "vol-0617a2d3ef4eab421" -> null
- volume_size = 5000 -> null
- volume_type = "gp2" -> null
+ ebs_block_device # forces replacement
+ delete_on_termination = true
+ device_name = "/dev/sde"
+ encrypted = true
+ iops = (known after apply)
+ kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d"
+ snapshot_id = (known after apply)
+ tags =
+ "AWSResoureceType" = "EC2"
+ "Account" = "MITSURV"
+ "ApplicationID" = "APP-00682"
+ "ApplicationName" = "MITCAPMARKET"
+ "Automation" = "PLACEHOLDER"
+ "BaseImageName" = "Add_Your_Base_AMI_Name"
+ "BusinessEntitiy" = "MIT"
+ "CostCentre" = "CC55219"
+ "DBVersion" = "N/A"
+ "DataClassification" = "3"
+ "Division" = "DEVOPS"
+ "Environment" = "NONPROD"
+ "Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "OSVersion" = "N/A"
+ "Project" = "SURV"
+ "ProjectCode" = "25127-100"
+ "Purpose" = "QA1"
+ "RelVersion" = "4.0.0.0.i2"
+ "ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
+ "VersionNumber" = "N/A"
+ "Workload" = "TEST"
+ "mount" = "/x04"
+ "node_type" = "master"
+ throughput = (known after apply)
+ volume_id = (known after apply)
+ volume_size = 5000
+ volume_type = "gp2"
~ enclave_options
~ enabled = false -> (known after apply)
+ ephemeral_block_device
+ device_name = (known after apply)
+ no_device = (known after apply)
+ virtual_name = (known after apply)
~ metadata_options
~ http_endpoint = "enabled" -> (known after apply)
~ http_put_response_hop_limit = 1 -> (known after apply)
~ http_tokens = "optional" -> (known after apply)
+ network_interface
+ delete_on_termination = (known after apply)
+ device_index = (known after apply)
+ network_interface_id = (known after apply)
~ root_block_device
delete_on_termination = true
~ device_name = "/dev/sda1" -> (known after apply)
encrypted = true
~ iops = 750 -> (known after apply)
kms_key_id = "arn:aws:kms:eu-west-2:946581213364:key/15dc10ff-885a-4217-ad60-05ef9682d34d"
tags =
"AWSResoureceType" = "EC2"
"Account" = "MITSURV"
"ApplicationID" = "APP-00682"
"ApplicationName" = "MITCAPMARKET"
"Automation" = "PLACEHOLDER"
"BaseImageName" = "Add_Your_Base_AMI_Name"
"BusinessEntitiy" = "MIT"
"CostCentre" = "CC55219"
"DBVersion" = "N/A"
"DataClassification" = "3"
"Division" = "DEVOPS"
"Environment" = "NONPROD"
"Name" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
"OSVersion" = "N/A"
"Project" = "SURV"
"ProjectCode" = "25127-100"
"Purpose" = "QA1"
"RelVersion" = "4.0.0.0.i2"
"ResourceName" = "MITSURV-NONPROD-MITCAPMARKET-SURV-DEVOPS-QA1-MN-1-EBS"
"VersionNumber" = "N/A"
"Workload" = "TEST"
"node_type" = "master"
~ throughput = 0 -> (known after apply)
~ volume_id = "vol-042ac0ffd687aec19" -> (known after apply)
volume_size = 250
volume_type = "gp2"
感谢您对理解此问题的支持?
【问题讨论】:
仅显示terraform apply
的一些输出不足以让任何人帮助您。您需要查看 terraform plan
输出,以了解 Terraform 决定需要销毁和重新创建一些资源的确切原因。
对不起,我已经用这个问题更新了计划输出。
【参考方案1】:
我在github 中找到了答案并解决了问题,希望这是这样做的正确方法。
lifecycle
ignore_changes = [ebs_block_device,user_data]
【讨论】:
以上是关于为啥 terraform 试图重建已经提供的基础设施?的主要内容,如果未能解决你的问题,请参考以下文章