From 55012f9ac04439d0cb13687c281f7dea563e19aa Mon Sep 17 00:00:00 2001 From: butomo1989 Date: Wed, 7 Nov 2018 16:29:14 +0100 Subject: [PATCH] Enable custom AMI which given from the user --- genymotion/example/sample_devices/aws.json | 3 ++- src/appium.sh | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/genymotion/example/sample_devices/aws.json b/genymotion/example/sample_devices/aws.json index 0aa08d4..663d1af 100755 --- a/genymotion/example/sample_devices/aws.json +++ b/genymotion/example/sample_devices/aws.json @@ -2,7 +2,8 @@ { "region": "eu-west-1", "android_version": "6.0", - "instance": "t2.small" + "instance": "t2.small", + "AMI": "ami-68d78411" }, { "region": "eu-west-1", diff --git a/src/appium.sh b/src/appium.sh index 42333a5..0f22b30 100644 --- a/src/appium.sh +++ b/src/appium.sh @@ -49,10 +49,12 @@ function prepare_geny_aws() { region=$(get_value '.region') android_version=$(get_value '.android_version') instance=$(get_value '.instance') + ami=$(get_value '.AMI') echo $region echo $android_version echo $instance + echo $ami aws_tf_content=$(cat <<_EOF variable "aws_region_$index" { @@ -137,7 +139,7 @@ resource "aws_key_pair" "geny_key_$index" { resource "aws_instance" "geny_aws_$index" { provider = "aws.provider_$index" - ami = "\${data.aws_ami.geny_aws_$index.id}" + ami="\${data.aws_ami.geny_aws_$index.id}" instance_type = "\${var.instance_type_$index}" vpc_security_group_ids = ["\${aws_security_group.geny_sg_$index.name}"] key_name = "\${aws_key_pair.geny_key_$index.key_name}" @@ -163,6 +165,14 @@ output "public_dns_$index" { _EOF ) echo "$aws_tf_content" > /root/aws_tf_$index.tf + + if [[ $ami != null ]]; then + echo "Custom AMI is found!" + sed -i "s/.*ami=.*/ ami=\"$ami\"/g" /root/aws_tf_$index.tf + else + echo "Custom AMI is not found. It will use the latest AMI!" + fi + ((index++)) ((port++)) done