我正在使用 aws 并使用 terraform 创建资源。我对资源进行了更改aws_lauch_configuration
并应用了 usign terraform。
Tf 代码是
resource "aws_launch_configuration" "app" {
name_prefix = var.ecs_launch_configuration_name_prefix
security_groups = [
aws_security_group.instance_sg.id,
]
key_name = aws_key_pair.deployer.key_name
image_id = var.ecs_launch_configuration_image_id
instance_type = var.ecs_launch_configuration_instance_type
iam_instance_profile = aws_iam_instance_profile.app.name
associate_public_ip_address = false
user_data = data.template_file.user_data.rendered
lifecycle {
create_before_destroy = true
}
}
Terraform 显示它首先将创建该资源,然后在 create_before_destroy 设置为 true 时之前销毁。因此,在创建资源后,teraform 无法删除较旧的资源。所以我从 aws 控制台手动删除了它,然后再次运行 terraform 脚本。
现在它显示被销毁的对象将被销毁。
# aws_launch_configuration.app (deposed object e9636964) will be destroyed
- resource "aws_launch_configuration" "app" {
- arn = "arn:aws:autoscaling:ap-south-1:989263488711:launchConfiguration:5c662048-79b0-4158-861a-df6f86d0641e:launchConfigurationName/staging-launch-config-20210723120615775100000001" -> null
- associate_public_ip_address = false -> null
- ebs_optimized = false -> null
- enable_monitoring = true -> null
- iam_instance_profile = "staging-ecs-instance-profile" -> null
- id = "staging-launch-config-20210723120615775100000001" -> null
- image_id = "ami-070ea05cb21034fd4" -> null
- instance_type = "t3.micro" -> null
- key_name = "deployer_key" -> null
- name = "staging-launch-config-20210723120615775100000001" -> null
- name_prefix = "staging-launch-config-" -> null
- security_groups = [
- "sg-0efdc5b4e5e0d5381",
] -> null
- user_data = "62fa54f43cbd35da831f418a9b62474d81b16795" -> null
- vpc_classic_link_security_groups = [] -> null
}
应用 terraform 后,它会抛出错误error deleting Autoscaling Launch Configuration (staging-launch-config-20210723120615775100000001): ValidationError: Launch configuration name not found - Launch configuration staging-launch-config-20210723120615775100000001 not found status code: 400, request id: 12e7aa05-f3b1-4d75-a5a5-2093df3e5838
我知道这个错误将被抛出,因为资源在 aws 上不存在(手动删除)。我试过terraform apply -refresh=true
了,但没有用。请帮我解决这个错误。