diff --git a/cli/src/providers/aws/InfrastructureBuilder.py b/cli/src/providers/aws/InfrastructureBuilder.py index 673b6befac..a57a6db2b9 100644 --- a/cli/src/providers/aws/InfrastructureBuilder.py +++ b/cli/src/providers/aws/InfrastructureBuilder.py @@ -141,6 +141,7 @@ def get_vm(self, component_key, vm_config, subnet, public_key_config, security_g vm.specification.subnet_name = subnet.specification.name vm.specification.key_name = public_key_config.specification.key_name vm.specification.use_network_security_groups = self.use_network_security_groups + vm.specification.availability_zone = subnet.specification.availability_zone if self.use_network_security_groups: vm.specification.security_groups = [security_group.specification.name] vm.specification.associate_public_ip = self.cluster_model.specification.cloud.use_public_ips @@ -152,7 +153,7 @@ def get_subnet(self, subnet_definition, component_key, vpc_name, index): subnet = self.get_config_or_default(self.docs, 'infrastructure/subnet') subnet.specification.vpc_name = vpc_name subnet.specification.cidr_block = subnet_definition['address_pool'] - + subnet.specification.availability_zone = subnet_definition['availability_zone'] subnet.specification.name = resource_name(self.cluster_prefix, self.cluster_name, 'subnet' + '-' + str(index), component_key) subnet.specification.cluster_name = self.cluster_name return subnet diff --git a/docs/changelogs/CHANGELOG-2.0.md b/docs/changelogs/CHANGELOG-2.0.md index f829a1fae1..da841f4c53 100644 --- a/docs/changelogs/CHANGELOG-2.0.md +++ b/docs/changelogs/CHANGELOG-2.0.md @@ -21,6 +21,7 @@ - [#2945](https://github.com/epiphany-platform/epiphany/issues/2945) - epicli apply sleeps 10 seconds after creating inventory - [#2968](https://github.com/epiphany-platform/epiphany/issues/2968) - `epicli init` should generate `specification.cloud.subscription_name` for minimal cluster config - [#2940](https://github.com/epiphany-platform/epiphany/issues/2940) - firewalld.service unit could not be found on host however ansible_facts sees it as defined +- [#2979](https://github.com/epiphany-platform/epiphany/issues/2979) - Restore the possibility of choosing the availability zone in AWS ### Updated diff --git a/schema/aws/defaults/epiphany-cluster.yml b/schema/aws/defaults/epiphany-cluster.yml index b7038b4249..f50a21cb6d 100644 --- a/schema/aws/defaults/epiphany-cluster.yml +++ b/schema/aws/defaults/epiphany-cluster.yml @@ -26,63 +26,74 @@ specification: configuration: default subnets: - address_pool: 10.1.1.0/24 + availability_zone: eu-west-2a kubernetes_node: count: 2 machine: kubernetes-node-machine configuration: default subnets: - address_pool: 10.1.1.0/24 + availability_zone: eu-west-2a logging: count: 1 machine: logging-machine configuration: default subnets: - address_pool: 10.1.3.0/24 + availability_zone: eu-west-2a monitoring: count: 1 machine: monitoring-machine configuration: default subnets: - address_pool: 10.1.4.0/24 + availability_zone: eu-west-2a kafka: count: 2 machine: kafka-machine configuration: default subnets: - address_pool: 10.1.5.0/24 + availability_zone: eu-west-2a postgresql: count: 0 machine: postgresql-machine configuration: default subnets: - address_pool: 10.1.6.0/24 + availability_zone: eu-west-2a load_balancer: count: 1 machine: load-balancer-machine configuration: default subnets: - address_pool: 10.1.7.0/24 + availability_zone: eu-west-2a rabbitmq: count: 0 machine: rabbitmq-machine configuration: default subnets: - address_pool: 10.1.8.0/24 + availability_zone: eu-west-2a opendistro_for_elasticsearch: count: 0 machine: logging-machine configuration: default subnets: - address_pool: 10.1.10.0/24 + availability_zone: eu-west-2a repository: count: 1 machine: repository-machine configuration: default subnets: - address_pool: 10.1.11.0/24 + availability_zone: eu-west-2a single_machine: count: 0 machine: single-machine configuration: default subnets: - address_pool: 10.1.1.0/24 + availability_zone: eu-west-2a diff --git a/schema/aws/defaults/infrastructure/subnet.yml b/schema/aws/defaults/infrastructure/subnet.yml index 7b41befa1f..84406b72af 100644 --- a/schema/aws/defaults/infrastructure/subnet.yml +++ b/schema/aws/defaults/infrastructure/subnet.yml @@ -7,3 +7,4 @@ specification: vpc_name: SET_BY_AUTOMATION cidr_block: SET_BY_AUTOMATION cluster_name: SET_BY_AUTOMATION + availability_zone: SET_BY_AUTOMATION diff --git a/schema/aws/defaults/infrastructure/virtual-machine.yml b/schema/aws/defaults/infrastructure/virtual-machine.yml index 7619d316c6..1283b24a6a 100644 --- a/schema/aws/defaults/infrastructure/virtual-machine.yml +++ b/schema/aws/defaults/infrastructure/virtual-machine.yml @@ -11,6 +11,7 @@ specification: subnet_name: SET_BY_AUTOMATION associate_public_ip: SET_BY_AUTOMATION use_network_security_groups: SET_BY_AUTOMATION + availability_zone: SET_BY_AUTOMATION security_groups: [] # SET_BY_AUTOMATION authorized_to_efs: false mount_efs: false diff --git a/schema/aws/validation/infrastructure/subnet.yml b/schema/aws/validation/infrastructure/subnet.yml index 9fb94851f9..0d49f682cd 100644 --- a/schema/aws/validation/infrastructure/subnet.yml +++ b/schema/aws/validation/infrastructure/subnet.yml @@ -11,3 +11,5 @@ properties: type: string cluster_name: type: string + availability_zone: + type: string diff --git a/schema/aws/validation/infrastructure/virtual-machine.yml b/schema/aws/validation/infrastructure/virtual-machine.yml index b166ae2889..7d49e1ea6e 100644 --- a/schema/aws/validation/infrastructure/virtual-machine.yml +++ b/schema/aws/validation/infrastructure/virtual-machine.yml @@ -19,6 +19,8 @@ properties: type: boolean use_network_security_groups: type: boolean + availability_zone: + type: string security_groups: type: array items: diff --git a/terraform/aws/infrastructure/subnet.j2 b/terraform/aws/infrastructure/subnet.j2 index af0bbeeecd..aeb61f82d5 100644 --- a/terraform/aws/infrastructure/subnet.j2 +++ b/terraform/aws/infrastructure/subnet.j2 @@ -13,6 +13,7 @@ resource "aws_subnet" "{{ specification.name }}" { vpc_id = aws_vpc.{{ specification.vpc_name }}.id cidr_block = "{{ specification.cidr_block }}" + availability_zone = "{{ specification.availability_zone }}" tags = { cluster_name = "{{ specification.cluster_name }}" diff --git a/terraform/aws/infrastructure/virtual-machine.j2 b/terraform/aws/infrastructure/virtual-machine.j2 index 0a1821eafe..586ef42e03 100644 --- a/terraform/aws/infrastructure/virtual-machine.j2 +++ b/terraform/aws/infrastructure/virtual-machine.j2 @@ -19,6 +19,7 @@ resource "aws_instance" "{{ specification.name }}" { {%- if specification.use_network_security_groups == true %} vpc_security_group_ids = [{% for security_group in specification.security_groups %}aws_security_group.{{ security_group }}.id{% if not loop.last %}, {% endif %}{% endfor %}] {%- endif %} + availability_zone = "{{ specification.availability_zone }}" # storage ebs_optimized = "{{ specification.ebs_optimized | lower }}" diff --git a/tests/unit/providers/aws/test_AWSConfigBuilder.py b/tests/unit/providers/aws/test_AWSConfigBuilder.py index bf60010eab..d646fb6d58 100644 --- a/tests/unit/providers/aws/test_AWSConfigBuilder.py +++ b/tests/unit/providers/aws/test_AWSConfigBuilder.py @@ -48,7 +48,8 @@ def test_get_efs_config_should_set_proper_values_to_model(): def test_get_subnet_config_should_set_proper_values_to_model(): cluster_model = get_cluster_model(cluster_name='TestCluster') component_value = dict_to_objdict({ - 'address_pool': '10.20.0.0/24' + 'address_pool': '10.20.0.0/24', + 'availability_zone': 'eu-westa' }) builder = InfrastructureBuilder([cluster_model]) @@ -57,6 +58,7 @@ def test_get_subnet_config_should_set_proper_values_to_model(): assert actual.specification.name == 'prefix-testcluster-component-subnet-1' assert actual.specification.vpc_name == 'my-test-vpc' assert actual.specification.cidr_block == '10.20.0.0/24' + assert actual.specification.availability_zone == 'eu-westa' def test_get_security_group_should_set_proper_values_to_model():