此问题与Terraform 0.12 版本
有关
嗨!我目前正在使用Terraform在团队中部署AWS EMR集群,每次我们添加新资源时,Terraform都会重新创建集群。我们集群的声明如下:
resource "aws_emr_cluster" "emr_spark_cluster" {
name = "whatever_name_to_emr_spark_cluster"
release_label = "emr-5.29.0"
applications = ["Spark"]
log_uri = "whatever_log_uri"
ec2_attributes {
subnet_id = var.vpc_public_subnets[0]
emr_managed_master_security_group = aws_security_group.emr_sg.id
emr_managed_slave_security_group = aws_security_group.emr_sg.id
instance_profile = aws_iam_instance_profile.instance_profile.arn
key_name = "whatever_name_to_ec2_attributes"
}
master_instance_group {
instance_type = var.emr_master_instance_type
}
core_instance_group {
instance_type = var.emr_core_instance_type
instance_count = var.emr_core_instance_count
ebs_config {
size = var.emr_core_ebs_size
type = whatever_type
volumes_per_instance = whatever_volumes_per_instance
}
}
tags = var.tags
service_role = aws_iam_role.emr_service.arn
}
基本上,我们使用master_instance_group
和core_instance_group
作为Terraform 0.12 docs suggest( 1 )
在已经部署了集群并尝试添加新资源的情况下,terraform apply
命令说需要重新创建集群(删除了所有无关的内容):
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
-/+ destroy and then create replacement
Terraform will perform the following actions:
# module.emr.aws_emr_cluster.emr_spark_cluster must be replaced
-/+ resource "aws_emr_cluster" "emr_spark_cluster" {
applications = [whatever_applications]]
- ebs_root_volume_size = 0 -> null
- instance_group {
- id = whatever_id -> null
- instance_count = 2 -> null
- instance_role = "CORE" -> null
- instance_type = whatever_the_instance_type -> null
- ebs_config {
- iops = 0 -> null
- size = whatever_size -> null
- type = whatever_type -> null
- volumes_per_instance = whatever_volumes_per_instance -> null
}
}
- instance_group {
- id = whatever_id -> null
- instance_count = whatever_instance_count -> null
- instance_role = "MASTER" -> null
- instance_type = whatever_the_instance_type -> null
- ebs_config {
- iops = 0 -> null
- size = whatever_size -> null
- type = whatever_type -> null
- volumes_per_instance = whatever_volumes_per_instance -> null
}
}
+ instance_group {
+ autoscaling_policy = (known after apply)
+ bid_price = (known after apply)
+ id = (known after apply)
+ instance_count = (known after apply)
+ instance_role = (known after apply)
+ instance_type = (known after apply)
+ name = (known after apply)
+ ebs_config {
+ iops = (known after apply)
+ size = (known after apply)
+ type = (known after apply)
+ volumes_per_instance = (known after apply)
}
}
~ master_instance_group {
~ id = whatever_id -> (known after apply)
instance_count = 1
instance_type = whatever_the_instance_type
- ebs_config {
- iops = 0 -> null
- size = whatever_size -> null
- type = whatever_type -> null
- volumes_per_instance = whatever_volumes_per_instance -> null
}
+ ebs_config {
+ iops = (known after apply)
+ size = (known after apply)
+ type = (known after apply)
+ volumes_per_instance = (known after apply)
}
}
}
基本上,我真正感兴趣的部分是instance_group
。我想这就是为什么需要重新创建集群的原因,因为当前的master_instance_group
和core_instance_group
属性不“保留”特定的实例组,而只是“保留”它们的类型和大小,对吧? >
由于这个原因,我尝试使用aws_emr_instance_group
资源尝试替换master_instance_group
和core_instance_group
属性,并通过cluster_id
将它们直接链接到集群属性。例如,{{1}中的aws_emr_instance_group
:
master_instances
但是在执行resource "aws_emr_instance_group" "master_instances" {
name = "emr_cluster_master_instances"
cluster_id = aws_emr_cluster.emr_spark_cluster.id
instance_type = var.emr_master_instance_type
instance_count = var.emr_master_instance_count
ebs_config {
iops = 0
size = var.emr_core_ebs_size
type = whatever_type
volumes_per_instance = whatever_volumes_per_instance
}
}
时,它失败并显示以下错误:
terraform plan
我不理解该错误,因为我正在将实例组与集群链接。
所以我的问题是:
module.emr.aws_emr_cluster.emr_spark_cluster: Creating...
Error: error running EMR Job Flow: ValidationException: Instance count must be greater than 0
,master_instance_type
和core_instance_type
吗?也许我在错误地使用core_instance_count
资源?aws_emr_instance_group
和master_instance_group
的预期行为?我的意思是,即使集群被破坏,也要避免创建特定的实例以使其处于活动状态?预先感谢
( 1 )我说“建议”是因为core_instance_group
,core_instance_type
和core_instance_count
等其他属性在Terraform 0.12中已弃用。