почему вложение целевой группы не работает как вложение тома - PullRequest
0 голосов
/ 18 февраля 2019

При использовании count (3) для ec2_instance, aws_volume_attachment и aws_lb_target_group_attachment я могу завершить один ec2_instance, и при следующем применении terraform он создаст только один отсутствующий экземпляр, одно вложение отсутствующего тома, но попытаетсяудалить и воссоздать все 3 вложения целевой группы.Это приводит к тому, что все 3 экземпляра ненадолго нездоровы в целевой группе, что означает, что все 3 запроса на отправку отправлены, хотя 2 из них исправны, а один нет.ожидается, что следующая терраформа будет применена для повторного создания zookeeper [1], kafka_att [1] и schemaRegistryTgAttach [1].

Приведенный выше код создает экземпляр [1] и volume_attachment [1], но не target_group_attachments.Если я удаляю блок жизненного цикла из target_group_attachments, он затем удаляет и заново создает все 3 ???Как я могу изменить его так, чтобы при создании одного экземпляра ec2 он создавал только одно вложение целевой группы?

Если я пытаюсь использовать тот же метод, что и для вложения тома ...

resource "aws_lb_target_group_attachment" "schemaRegistryTgAttach" {
count = "${var.zookeeper-max}"
target_group_arn = 
"${aws_alb_target_group.KafkaSchemaRegistryTG.arn}"
target_id = "${element(aws_instance.zookeeper.*.id,count.index)}"
depends_on  = ["aws_instance.zookeeper"]
lifecycle {
 ignore_changes = ["aws_instance.zookeeper"]
}

} затем он не создает вложения TG, но создает правильное вложение тома ... вывод плана: -

+ aws_instance.zookeeper[0]
id:                                        <computed>
ami:                                       "ami-09693313102a30b2c"
arn:                                       <computed>
associate_public_ip_address:               "false"
availability_zone:                         <computed>
cpu_core_count:                            <computed>
cpu_threads_per_core:                      <computed>
credit_specification.#:                    "1"
credit_specification.0.cpu_credits:        "unlimited"
disable_api_termination:                   "true"
ebs_block_device.#:                        <computed>
ebs_optimized:                             "false"
ephemeral_block_device.#:                  <computed>
get_password_data:                         "false"
host_id:                                   <computed>
iam_instance_profile:                      "devl-ZOOKEEPER_IAM_PROFILE"
instance_state:                            <computed>
instance_type:                             "t3.small"
ipv6_address_count:                        <computed>
ipv6_addresses.#:                          <computed>
key_name:                                  "devl-key"
monitoring:                                "false"
network_interface.#:                       <computed>
network_interface_id:                      <computed>
password_data:                             <computed>
placement_group:                           <computed>
primary_network_interface_id:              <computed>
private_dns:                               <computed>
private_ip:                                <computed>
public_dns:                                <computed>
public_ip:                                 <computed>
root_block_device.#:                       "1"
root_block_device.0.delete_on_termination: "true"
root_block_device.0.volume_id:             <computed>
root_block_device.0.volume_size:           "16"
root_block_device.0.volume_type:           "gp2"
security_groups.#:                         <computed>
subnet_id:                                 "subnet-5b8d8200"
tags.%:                                    "3"
tags.Description:                          "Do not terminate more than 
one at a time"
tags.Env:                                  "devl"
tags.Name:                                 "devl-zookeeper-0"
tenancy:                                   <computed>
user_data:                                 
"70fd2ae9f7da42e2fb15328cd6539c4f7ed4a5be"
volume_tags.%:                             <computed>
vpc_security_group_ids.#:                  "1"
vpc_security_group_ids.3423986071:         "sg-03911aa28dbcb3f20"

+ aws_volume_attachment.kafka_att[0]
id:                                        <computed>
device_name:                               "/dev/sdh"
instance_id:                               
"${element(aws_instance.zookeeper.*.id,count.index)}"
volume_id:                                 "vol-021d1530117f31905"

если, однако, я удалю блок жизненного цикла вложения целевой группы, онпытается уничтожить и воссоздать все 3 вложения целевой группы.

+ aws_instance.zookeeper[0] 
id: ami: "ami-09693313102a30b2c" 
arn: 
associate_public_ip_address: "false" 
availability_zone: 
cpu_core_count: 
cpu_threads_per_core: 
credit_specification.#: "1" 
credit_specification.0.cpu_credits: "unlimited" 
disable_api_termination: "true" 
ebs_block_device.#: 
ebs_optimized: "false" 
ephemeral_block_device.#: 
get_password_data: "false" 
host_id: 
iam_instance_profile: "devl-ZOOKEEPER_IAM_PROFILE" 
instance_state: 
instance_type: "t3.small" 
ipv6_address_count: ipv6_addresses.#: 
key_name: "devl-key" 
monitoring: "false" 
network_interface.#: 
network_interface_id: 
password_data: 
placement_group: 
primary_network_interface_id: 
private_dns: private_ip: public_dns: 
public_ip: 
root_block_device.#: "1" 
root_block_device.0.delete_on_termination: "true" 
root_block_device.0.volume_id: 
root_block_device.0.volume_size: "16" 
root_block_device.0.volume_type: "gp2" 
security_groups.#: 
source_dest_check: "false" 
subnet_id: "subnet-5b8d8200" 
tags.%: "3" 
tags.Description: "Do not terminate more than one at a time" 
tags.Env: "devl" 
tags.Name: "devl-zookeeper-0" 
tenancy: 
user_data: "70fd2ae9f7da42e2fb15328cd6539c4f7ed4a5be" 
volume_tags.%: 
vpc_security_group_ids.#: "1" 
vpc_security_group_ids.3423986071: "sg-03911aa28dbcb3f20"

-/+ aws_lb_target_group_attachment.SchemaRegistryTgAttach[0] (new 
resource required) 
id: "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034-20190218210336558900000001" => (forces new resource) 
port: "8081" => "8081" 
target_group_arn: "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034" => "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034" target_id: "i-03ed28ab175c0f684" => "${element(aws_volume_attachment.kafka_att.*.instance_id,count.index)}" (forces new resource)

-/+ aws_lb_target_group_attachment.SchemaRegistryTgAttach[1] (new resource required) id: "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034-20190218210336576900000002" => (forces new resource) 
port: "8081" => "8081" 
target_group_arn: "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034" => "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034" 
target_id: "i-0b39bd7244f32809f" => "${element(aws_volume_attachment.kafka_att.*.instance_id,count.index)}" (forces new resource)

-/+ aws_lb_target_group_attachment.SchemaRegistryTgAttach[2] (new resource required) 
id: "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034-20190218210336671000000003" => (forces new resource) 
port: "8081" => "8081" 
target_group_arn: "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034" => "arn:aws:elasticloadbalancing:eu-west-1:544611607123:targetgroup/devl-KafkaSchemaRegistryTG/46193714a87ea034" 
target_id: "i-0bbd8d3a10890b94c" => "${element(aws_volume_attachment.kafka_att.*.instance_id,count.index)}" (forces new resource)

+ aws_volume_attachment.kafka_att[0] 
id: 
device_name: "/dev/sdh" 
instance_id: "${element(aws_instance.zookeeper.*.id,count.index)}" 
volume_id: "vol-021d1530117f31905"

Как мне заставить его вести себя как вложение тома ... так что если экземпляр 3 умер, tf apply создаст вложение тома 3 и толькоПриложение TG 3.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...