From 8f20f9f2f05beb448fac8a52823bd779a56d9914 Mon Sep 17 00:00:00 2001 From: erzetpe Date: Fri, 29 Mar 2019 16:34:00 +0100 Subject: [PATCH] Fix to terraform helper and add changes list to more pythonic way (#193) * Item: #58 Desc: Change template to match query parameter from ansible inventory creation * Item: #58 Desc: Changed list creation to more pythonic way * Item: #58 Desc: Fix issue with terraform file helper --- core/src/epicli/cli/engine/AnsibleInventoryCreator.py | 4 ++-- core/src/epicli/cli/engine/aws/AWSAPIProxy.py | 2 +- core/src/epicli/cli/engine/aws/AWSConfigBuilder.py | 2 +- core/src/epicli/cli/helpers/doc_list_helpers.py | 2 +- core/src/epicli/cli/helpers/terraform_file_helper.py | 6 +++--- .../cli/static/terraform_templates_aws/vm_template.tf.j2 | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/epicli/cli/engine/AnsibleInventoryCreator.py b/core/src/epicli/cli/engine/AnsibleInventoryCreator.py index 8e8d756fa2..c4211ca1a6 100644 --- a/core/src/epicli/cli/engine/AnsibleInventoryCreator.py +++ b/core/src/epicli/cli/engine/AnsibleInventoryCreator.py @@ -25,7 +25,7 @@ def create(self): save_inventory(inventory, self.cluster_model.specification.name) def get_inventory(self): - inventory = list() + inventory = [] for component_key, component_value in self.cluster_model.specification.components.items(): if component_value.count < 1: continue @@ -56,7 +56,7 @@ def group_duplicated(inventory): if host not in groups[item.role]: groups[item.role].append(host) - result = list() + result = [] for key, value in groups.items(): result.append(AnsibleInventoryItem(key, value)) return result diff --git a/core/src/epicli/cli/engine/aws/AWSAPIProxy.py b/core/src/epicli/cli/engine/aws/AWSAPIProxy.py index 4e7ed82b3a..3f7c6363c1 100644 --- a/core/src/epicli/cli/engine/aws/AWSAPIProxy.py +++ b/core/src/epicli/cli/engine/aws/AWSAPIProxy.py @@ -48,7 +48,7 @@ def get_ips_for_feature(self, feature_key, look_for_public_ip=False): }] ) - result = list() + result = [] for instance in running_instances: if look_for_public_ip: result.append(AnsibleHostModel(instance.public_dns_name, instance.public_ip_address)) diff --git a/core/src/epicli/cli/engine/aws/AWSConfigBuilder.py b/core/src/epicli/cli/engine/aws/AWSConfigBuilder.py index 56d45c57fe..8c95ce6fe6 100644 --- a/core/src/epicli/cli/engine/aws/AWSConfigBuilder.py +++ b/core/src/epicli/cli/engine/aws/AWSConfigBuilder.py @@ -7,7 +7,7 @@ class AWSConfigBuilder(InfrastructureConfigBuilder): def build(self, cluster_model, user_input): - result = list() + result = [] vpc_config = self.get_vpc_config(cluster_model, user_input) result.append(vpc_config) vpc_name = vpc_config.specification.name diff --git a/core/src/epicli/cli/helpers/doc_list_helpers.py b/core/src/epicli/cli/helpers/doc_list_helpers.py index 111b3400d9..43536ec516 100644 --- a/core/src/epicli/cli/helpers/doc_list_helpers.py +++ b/core/src/epicli/cli/helpers/doc_list_helpers.py @@ -9,7 +9,7 @@ def select_first(documents, query): def select_all(documents, query): if documents is not None: - result = list() + result = [] for x in documents: if query(x): result.append(x) diff --git a/core/src/epicli/cli/helpers/terraform_file_helper.py b/core/src/epicli/cli/helpers/terraform_file_helper.py index 3bcc117f51..350ee88f9c 100644 --- a/core/src/epicli/cli/helpers/terraform_file_helper.py +++ b/core/src/epicli/cli/helpers/terraform_file_helper.py @@ -11,10 +11,10 @@ def generate_terraform_file(infrastructure, template_generator, template_generat template_generator_config. templates_paths) - if yaml_document.kind != "epiphany-cluster": - terraform_file_name = "{:03d}".format(idx + 1) + "_" + yaml_document.specification.name + ".tf" + if yaml_document["kind"] != "epiphany-cluster": + terraform_file_name = "{:03d}".format(idx + 1) + "_" + yaml_document["specification"]["name"] + ".tf" else: - terraform_file_name = "000_" + yaml_document.name + ".tf" + terraform_file_name = "000_" + yaml_document["specification"]["name"] + ".tf" terraform_output_file_path = os.path.join(terraform_build_directory, terraform_file_name) diff --git a/core/src/epicli/cli/static/terraform_templates_aws/vm_template.tf.j2 b/core/src/epicli/cli/static/terraform_templates_aws/vm_template.tf.j2 index ebab3d8ac3..e2d9da7a3b 100644 --- a/core/src/epicli/cli/static/terraform_templates_aws/vm_template.tf.j2 +++ b/core/src/epicli/cli/static/terraform_templates_aws/vm_template.tf.j2 @@ -35,7 +35,7 @@ resource "aws_autoscaling_group" "{{ specification.name }}" { tag { {%- for tag_key, tag_value in tag.items() %} key = "{{ tag_key }}" - value = "{% if tag_value is defined and tag_value|length %}{{ tag_value }}{% else %}-{% endif %}" + value = "{{ tag_value }}" {%- endfor %} propagate_at_launch = "true" }