避免使用Terraform重新创建EMR群集

时间:2020-07-13 15:07:03

标签: terraform amazon-emr

此问题与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_groupcore_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_groupcore_instance_group属性不“保留”特定的实例组,而只是“保留”它们的类型和大小,对吧? >

由于这个原因,我尝试使用aws_emr_instance_group资源尝试替换master_instance_groupcore_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_typecore_instance_type吗?也许我在错误地使用core_instance_count资源?
  • 是否有可能是属性aws_emr_instance_groupmaster_instance_group的预期行为?我的意思是,即使集群被破坏,也要避免创建特定的实例以使其处于活动状态?

预先感谢

1 我说“建议”是因为core_instance_groupcore_instance_typecore_instance_count等其他属性在Terraform 0.12中已弃用

0 个答案:

没有答案