From 0310e35da461d43baf9c75f180dd229ba6ba78da Mon Sep 17 00:00:00 2001 From: iuliana Date: Fri, 15 Jul 2022 14:58:57 +0100 Subject: [PATCH] added a few state parser polished and fixed the tests --- .../terraform/parser/StateParser.java | 52 ++--- .../TerraformConfigurationLiveTest.java | 21 +- .../TerraformConfigurationYamlTest.java | 24 +- .../TerraformJsonPlanParsingTest.java | 11 + .../blueprints/tf-asg-cfg-in-blueprint.bom | 5 +- .../blueprints/tf-cfg-in-artifactory.bom | 1 + .../blueprints/tf-cfg-in-blueprint.bom | 4 +- .../resources/blueprints/tf-cfg-in-bundle.bom | 1 + .../blueprints/tf-cfg-over-https.bom | 1 + .../blueprints/tf-secure-cfg-over-https.bom | 1 + .../blueprints/tf-state-in-artifactory.bom | 8 +- src/test/resources/plans/create-instance.tf | 3 +- .../resources/plans/create-security-group.tf | 2 +- .../resources/state/aws-instance-state.json | 210 ++++++++++++++++++ 14 files changed, 290 insertions(+), 54 deletions(-) create mode 100644 src/test/resources/state/aws-instance-state.json diff --git a/src/main/java/io/cloudsoft/terraform/parser/StateParser.java b/src/main/java/io/cloudsoft/terraform/parser/StateParser.java index dcabb15..61b24a5 100644 --- a/src/main/java/io/cloudsoft/terraform/parser/StateParser.java +++ b/src/main/java/io/cloudsoft/terraform/parser/StateParser.java @@ -34,7 +34,7 @@ public final class StateParser { */ public static final ImmutableList PROBLEMATIC_RESOURCES = ImmutableList.of("aws_emr_cluster.spark_cluster"); - private static Predicate providerPredicate = (Predicate) ple -> ple.getProvider() != PlanLogEntry.Provider.NOT_SUPPORTED; + private static Predicate providerPredicate = (Predicate) planLogEntry -> planLogEntry.getProvider() != PlanLogEntry.Provider.NOT_SUPPORTED; private static Predicate changeSummaryPredicate = (Predicate) ple -> ple.type == PlanLogEntry.LType.CHANGE_SUMMARY; private static Predicate outputsPredicate = (Predicate) ple -> ple.type == PlanLogEntry.LType.OUTPUTS; private static Predicate plannedChangedPredicate = (Predicate) ple -> ple.type == PlanLogEntry.LType.PLANNED_CHANGE; @@ -68,36 +68,36 @@ public static Map parseResources(final String state){ Map resourceBody = new LinkedHashMap<>(); //if (resource.has("mode") && "managed".equals(resource.get("mode").asText())) { - result.put(resource.get("address").asText(), resourceBody); + result.put(resource.get("address").asText(), resourceBody); - resourceBody.put("resource.address", resource.get("address").asText()); - resourceBody.put("resource.mode", resource.get("mode").asText()); - resourceBody.put("resource.type", resource.get("type").asText()); - resourceBody.put("resource.name", resource.get("name").asText()); - resourceBody.put("resource.provider", resource.get("provider_name").asText()); - if(resource.has("values")) { - Iterator> it = resource.get("values").fields(); - while(it.hasNext()) { - Map.Entry value = it.next(); - if(isNotBlankPredicate.test(value.getValue())) { - if((resourceBody.get("resource.address").toString().startsWith(GOOGLE.getPrefix()) && value.getKey().equals("cluster_config"))){ - parseClusterData(value.getValue(), "value.cluster_config", resourceBody); - } else { - resourceBody.put("value." + value.getKey(), value.getValue().asText()); - } + resourceBody.put("resource.address", resource.get("address").asText()); + resourceBody.put("resource.mode", resource.get("mode").asText()); + resourceBody.put("resource.type", resource.get("type").asText()); + resourceBody.put("resource.name", resource.get("name").asText()); + resourceBody.put("resource.provider", resource.get("provider_name").asText()); + if(resource.has("values")) { + Iterator> it = resource.get("values").fields(); + while(it.hasNext()) { + Map.Entry value = it.next(); + if(isNotBlankPredicate.test(value.getValue())) { + if((resourceBody.get("resource.address").toString().startsWith(GOOGLE.getPrefix()) && value.getKey().equals("cluster_config"))){ + parseClusterData(value.getValue(), "value.cluster_config", resourceBody); + } else { + resourceBody.put("value." + value.getKey(), value.getValue() instanceof TextNode? value.getValue().asText() : value.getValue().toString()); } } } + } - if(resource.has("sensitive_values")) { - Iterator> it = resource.get("sensitive_values").fields(); - while(it.hasNext()) { - Map.Entry value = it.next(); - if(isNotBlankPredicate.test(value.getValue())) { - resourceBody.put("sensitive.value." + value.getKey(), value.getValue().asText()); - } + if(resource.has("sensitive_values")) { + Iterator> it = resource.get("sensitive_values").fields(); + while(it.hasNext()) { + Map.Entry value = it.next(); + if(isNotBlankPredicate.test(value.getValue())) { + resourceBody.put("sensitive.value." + value.getKey(), value.getValue() instanceof TextNode? value.getValue().asText() : value.getValue().toString()); } } + } //} }); @@ -156,10 +156,10 @@ public static Map parsePlanLogEntries(final String planLogEntrie try { return objectMapper.readValue(log, PlanLogEntry.class); } catch (JsonProcessingException e) { - LOG.warn("Unable to parse plan log entry: "+log, e); + e.printStackTrace(); } return null; - }).filter(x -> x!=null).collect(Collectors.toList()); + }).collect(Collectors.toList()); Map result = new HashMap<>(); diff --git a/src/test/java/io/cloudsoft/terraform/TerraformConfigurationLiveTest.java b/src/test/java/io/cloudsoft/terraform/TerraformConfigurationLiveTest.java index eafd483..1e2827b 100644 --- a/src/test/java/io/cloudsoft/terraform/TerraformConfigurationLiveTest.java +++ b/src/test/java/io/cloudsoft/terraform/TerraformConfigurationLiveTest.java @@ -10,7 +10,7 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.core.entity.Attributes; -import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.Dumper; import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; import org.apache.brooklyn.entity.group.DynamicGroup; import org.apache.brooklyn.entity.software.base.SoftwareProcess; @@ -31,6 +31,7 @@ public class TerraformConfigurationLiveTest extends TerraformConfigurationLiveTe public void testCreateSecurityGroup() throws Exception { terraformConfiguration = app.createAndManageChild(EntitySpec.create(TerraformConfiguration.class) .configure(TerraformConfiguration.CONFIGURATION_URL, "classpath://plans/create-security-group.tf") + .configure("tf.search", true) .configure(SoftwareProcess.SHELL_ENVIRONMENT, env)); app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); assertAttributeEqualsEventually(terraformConfiguration, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); @@ -39,7 +40,7 @@ public void testCreateSecurityGroup() throws Exception { Asserts.continually(new SensorSupplier<>(terraformConfiguration, TerraformConfiguration.STATE), input -> input == null || !input.containsKey("ERROR")); - Entities.dumpInfo(app); + Dumper.dumpInfo(app); LOG.debug("Stopping application ..."); app.stop(); } @@ -48,6 +49,7 @@ public void testCreateSecurityGroup() throws Exception { public void testCreateInstance() throws Exception { terraformConfiguration = app.createAndManageChild(EntitySpec.create(TerraformConfiguration.class) .configure(TerraformConfiguration.CONFIGURATION_URL, "classpath://plans/create-instance.tf") + .configure("tf.search", true) .configure(SoftwareProcess.SHELL_ENVIRONMENT, env)); app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); @@ -55,8 +57,7 @@ public void testCreateInstance() throws Exception { assertAttributeEqualsEventually(terraformConfiguration, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(terraformConfiguration, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertAttributeEventuallyNonNull(terraformConfiguration, TerraformConfiguration.OUTPUT); - - Entities.dumpInfo(app); + Dumper.dumpInfo(app); // Terraform can take more than thirty seconds to destroy the instance which // trips tearDown's timeout. Stop the application here instead. @@ -68,11 +69,12 @@ public void testCreateInstance() throws Exception { public void testCreateInstanceWithDynamicGroups() throws Exception { terraformConfiguration = app.createAndManageChild(EntitySpec.create(TerraformConfiguration.class) .configure(TerraformConfiguration.CONFIGURATION_URL, "classpath://plans/create-instance.tf") + .configure("tf.search", true) .configure(SoftwareProcess.SHELL_ENVIRONMENT, env)); - terraformConfiguration - .addChild(EntitySpec.create(DynamicGroup.class) - .configure(DynamicGroup.ENTITY_FILTER, - ResourceType.resourceType("aws_instance"))); + terraformConfiguration + .addChild(EntitySpec.create(DynamicGroup.class) + .configure(DynamicGroup.ENTITY_FILTER, + ResourceType.resourceType("aws_instance"))); app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); assertNotNull(terraformConfiguration.getAttribute(TerraformConfiguration.HOSTNAME)); @@ -83,8 +85,7 @@ public void testCreateInstanceWithDynamicGroups() throws Exception { for (Entity child : terraformConfiguration.getChildren()) { System.out.println(child.getDisplayName()); } - - Entities.dumpInfo(app); + Dumper.dumpInfo(app); // Terraform can take more than thirty seconds to destroy the instance which // trips tearDown's timeout. Stop the application here instead. diff --git a/src/test/java/io/cloudsoft/terraform/TerraformConfigurationYamlTest.java b/src/test/java/io/cloudsoft/terraform/TerraformConfigurationYamlTest.java index 6edc3da..cfeba92 100644 --- a/src/test/java/io/cloudsoft/terraform/TerraformConfigurationYamlTest.java +++ b/src/test/java/io/cloudsoft/terraform/TerraformConfigurationYamlTest.java @@ -15,6 +15,7 @@ import org.testng.annotations.Test; import java.util.Collection; +import java.util.Objects; import static org.apache.brooklyn.core.entity.EntityAsserts.assertAttributeEqualsEventually; @@ -54,9 +55,8 @@ public void testDeployFromAWSAndFromCfgInBundle() throws Exception { Entity entity = Iterables.getOnlyElement(app.getChildren()); Assert.assertTrue(entity instanceof TerraformConfiguration); - EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.isApplied"), v -> v.equals("true")); + EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.applied"), Objects::nonNull); - Assert.assertTrue(((Integer) entity.getChildren().size()).equals(1)); Entity resource = Iterables.getOnlyElement(entity.getChildren()); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.address"), v -> v.equals("aws_instance.web")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.mode"), v -> v.equals("managed")); @@ -66,7 +66,7 @@ public void testDeployFromAWSAndFromCfgInBundle() throws Exception { EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.status"), v -> v.equals("running")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.ami"), v -> v.equals("\"ami-02df9ea15c1778c9c\"")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.instance_type"), v -> v.equals("\"t2.micro\"")); - EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.tags"), v -> v.equals("{\"Name\":\"terraform-test-cfg-in-bundle\"}")); + EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.tags"), v -> v.contains("\"Name\":\"terraform-test-cfg-in-bundle\"")); // gracefully shutdown and test children are stopped @@ -80,10 +80,11 @@ public void testDeployFromLocalhostAndFromCfgInBlueprint() throws Exception { Application app = deploy("localhost_location", "classpath://blueprints/tf-cfg-in-blueprint.bom"); Entity entity = Iterables.getOnlyElement(app.getChildren()); + Assert.assertTrue(entity instanceof TerraformConfiguration); - EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.isApplied"), v -> v.equals("true")); + EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.applied"), Objects::nonNull); + EntityAsserts.assertPredicateEventuallyTrue(entity, entity1 -> ((Integer) entity1.getChildren().size()).equals(1)); - Assert.assertTrue(((Integer) entity.getChildren().size()).equals(1)); Entity resource = Iterables.getOnlyElement(entity.getChildren()); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.address"), v -> v.equals("aws_instance.example1")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.mode"), v -> v.equals("managed")); @@ -108,9 +109,10 @@ public void testDeployFromLocalhostFromCfgFileInArtifactory() throws Exception { Entity entity = Iterables.getOnlyElement(app.getChildren()); Assert.assertTrue(entity instanceof TerraformConfiguration); - EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.isApplied"), v -> v.equals("true")); - Assert.assertTrue(((Integer) entity.getChildren().size()).equals(1)); + EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.applied"), Objects::nonNull); + EntityAsserts.assertPredicateEventuallyTrue(entity, entity1 -> ((Integer) entity1.getChildren().size()).equals(1)); + Entity resource = Iterables.getOnlyElement(entity.getChildren()); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.address"), v -> v.equals("aws_instance.web")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.mode"), v -> v.equals("managed")); @@ -120,7 +122,7 @@ public void testDeployFromLocalhostFromCfgFileInArtifactory() throws Exception { EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.status"), v -> v.equals("running")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.ami"), v -> v.equals("\"ami-02df9ea15c1778c9c\"")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.instance_type"), v -> v.equals("\"t2.micro\"")); - EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.tags"), v -> v.equals("{\"Name\":\"terraform-test-cfg-with-input-vars\"}")); + EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.tags"), v -> v.contains("\"Name\":\"terraform-test-cfg-with-input-vars\"")); // gracefully shutdown and test children are stopped ((BasicApplication)app).stop(); @@ -134,9 +136,9 @@ public void testDeployFromLocalhostFromCfgZipOverHttps() throws Exception { Entity entity = Iterables.getOnlyElement(app.getChildren()); Assert.assertTrue(entity instanceof TerraformConfiguration); - EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.isApplied"), v -> v.equals("true")); + EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.applied"), Objects::nonNull); + EntityAsserts.assertPredicateEventuallyTrue(entity, entity1 -> ((Integer) entity1.getChildren().size()).equals(1)); - Assert.assertTrue(((Integer) entity.getChildren().size()).equals(1)); Entity resource = Iterables.getOnlyElement(entity.getChildren()); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.address"), v -> v.equals("aws_instance.example")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.mode"), v -> v.equals("managed")); @@ -146,7 +148,7 @@ public void testDeployFromLocalhostFromCfgZipOverHttps() throws Exception { EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.status"), v -> v.equals("running")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.ami"), v -> v.equals("\"ami-02df9ea15c1778c9c\"")); EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.instance_type"), v -> v.equals("\"t1.micro\"")); - EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.tags"), v -> v.equals("{\"Name\":\"terraform-test-cfg-in-zip-in-bucket\"}")); + EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.value.tags"), v -> v.contains("\"Name\":\"terraform-test-cfg-in-zip-in-bucket\"")); // gracefully shutdown and test children are stopped ((BasicApplication)app).stop(); diff --git a/src/test/java/io/cloudsoft/terraform/TerraformJsonPlanParsingTest.java b/src/test/java/io/cloudsoft/terraform/TerraformJsonPlanParsingTest.java index 57b535d..04df2aa 100644 --- a/src/test/java/io/cloudsoft/terraform/TerraformJsonPlanParsingTest.java +++ b/src/test/java/io/cloudsoft/terraform/TerraformJsonPlanParsingTest.java @@ -46,6 +46,17 @@ public void readManagedResources() throws IOException { assertTrue(resources.containsKey("aws_instance.example1")); } + @Test + public void checkAWSTags() throws IOException { + final String state = loadTestData("state/aws-instance-state.json"); + + Map resources = StateParser.parseResources(state); + assertEquals(resources.size(), 1); + assertTrue(resources.containsKey("aws_instance.example1")); + assertTrue(((Map)resources.get("aws_instance.example1")).containsKey("value.tags")); + assertTrue(((Map)resources.get("aws_instance.example1")).containsKey("value.tags_all")); + } + @Test public void readVSManagedResources() throws IOException { final String state = loadTestData("state/vs-state.json"); diff --git a/src/test/resources/blueprints/tf-asg-cfg-in-blueprint.bom b/src/test/resources/blueprints/tf-asg-cfg-in-blueprint.bom index 33ad3ba..7a12d0b 100644 --- a/src/test/resources/blueprints/tf-asg-cfg-in-blueprint.bom +++ b/src/test/resources/blueprints/tf-asg-cfg-in-blueprint.bom @@ -1,7 +1,9 @@ +location: localhost services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true # requires aws cli + creds installed on the machine deploying this tf.configuration.contents: | provider "aws" { @@ -26,7 +28,8 @@ services: } tags = { - Name = "TestSG-KillMePlease" + Name = "Test-Brooklyn-Terraform-KillMePlease" + Purpose = "Test-Brooklyn-Terraform-KillMePlease" } } diff --git a/src/test/resources/blueprints/tf-cfg-in-artifactory.bom b/src/test/resources/blueprints/tf-cfg-in-artifactory.bom index 2e816bd..6ed366e 100644 --- a/src/test/resources/blueprints/tf-cfg-in-artifactory.bom +++ b/src/test/resources/blueprints/tf-cfg-in-artifactory.bom @@ -2,6 +2,7 @@ services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true # Fetching archives over HTTP tf.configuration.url: 'https://artifactory.cloudsoftcorp.com/artifactory/libs-release-local/io/cloudsoft/packs/instance-with-creds.tf' diff --git a/src/test/resources/blueprints/tf-cfg-in-blueprint.bom b/src/test/resources/blueprints/tf-cfg-in-blueprint.bom index 0e44101..3c6cf01 100644 --- a/src/test/resources/blueprints/tf-cfg-in-blueprint.bom +++ b/src/test/resources/blueprints/tf-cfg-in-blueprint.bom @@ -2,6 +2,7 @@ services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true # requires aws cli + creds installed on the machine deploying this tf.configuration.contents: | provider "aws" { @@ -12,6 +13,7 @@ services: ami = "ami-02df9ea15c1778c9c" instance_type = "t1.micro" tags = { - Name = "terraform-test-cfg-in-blueprint" + Name = "Test-Brooklyn-Terraform-KillMePlease" + Purpose = "terraform-test-cfg-in-blueprint" } } \ No newline at end of file diff --git a/src/test/resources/blueprints/tf-cfg-in-bundle.bom b/src/test/resources/blueprints/tf-cfg-in-bundle.bom index 56bfdf9..4f92689 100644 --- a/src/test/resources/blueprints/tf-cfg-in-bundle.bom +++ b/src/test/resources/blueprints/tf-cfg-in-bundle.bom @@ -2,6 +2,7 @@ services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true # requires aws cli + creds installed on the machine deploying this # Fetching archives over HTTP tf.configuration.url: classpath://plans/create-instance.tf diff --git a/src/test/resources/blueprints/tf-cfg-over-https.bom b/src/test/resources/blueprints/tf-cfg-over-https.bom index ef24060..26c1901 100644 --- a/src/test/resources/blueprints/tf-cfg-over-https.bom +++ b/src/test/resources/blueprints/tf-cfg-over-https.bom @@ -2,6 +2,7 @@ services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true # requires aws cli + creds installed on the machine deploying this or add 'shell.env' # Fetching archives over HTTP tf.configuration.url: https://artifactory.cloudsoftcorp.com/artifactory/libs-release-local/io/cloudsoft/packs/tf-deployment.zip?archive=zip diff --git a/src/test/resources/blueprints/tf-secure-cfg-over-https.bom b/src/test/resources/blueprints/tf-secure-cfg-over-https.bom index a280dbf..f90b529 100644 --- a/src/test/resources/blueprints/tf-secure-cfg-over-https.bom +++ b/src/test/resources/blueprints/tf-secure-cfg-over-https.bom @@ -4,6 +4,7 @@ services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true # requires aws cli + creds installed on the machine deploying this or add 'shell.env' # Fetching archives over HTTP tf.configuration.url: https://artifactory.cloudsoftcorp.com/artifactory/libs-release-local/io/cloudsoft/packs/multiple-config.zip diff --git a/src/test/resources/blueprints/tf-state-in-artifactory.bom b/src/test/resources/blueprints/tf-state-in-artifactory.bom index 33a22b1..ab629af 100644 --- a/src/test/resources/blueprints/tf-state-in-artifactory.bom +++ b/src/test/resources/blueprints/tf-state-in-artifactory.bom @@ -2,6 +2,7 @@ services: - type: terraform name: Terraform Configuration brooklyn.config: + tf.search: true tf.configuration.contents: | terraform { backend "artifactory" { @@ -15,14 +16,15 @@ services: provider "aws" { region = "eu-west-1" - access_key = "" - secret_key = "" + access_key = "" + secret_key = "" } resource "aws_instance" "example1" { ami = "ami-02df9ea15c1778c9c" instance_type = "t1.micro" tags = { - Name = "terraform-test-state-in-artifactory" + Name = "Test-Brooklyn-Terraform-KillMePlease" + Purpose = "terraform-test-state-in-artifactory" } } \ No newline at end of file diff --git a/src/test/resources/plans/create-instance.tf b/src/test/resources/plans/create-instance.tf index ca442e0..2440cd1 100644 --- a/src/test/resources/plans/create-instance.tf +++ b/src/test/resources/plans/create-instance.tf @@ -24,7 +24,8 @@ resource "aws_instance" "web" { instance_type = "t2.micro" tags = { - Name = "terraform-test-cfg-in-bundle" + Name = "Test-Brooklyn-Terraform-KillMePlease" + Purpose = "terraform-test-cfg-in-bundle" } # Lookup the correct AMI based on the region diff --git a/src/test/resources/plans/create-security-group.tf b/src/test/resources/plans/create-security-group.tf index e66fa5e..2e88fcb 100644 --- a/src/test/resources/plans/create-security-group.tf +++ b/src/test/resources/plans/create-security-group.tf @@ -16,7 +16,7 @@ resource "aws_security_group" "allow_all" { } tags = { - Name = "TestSG-KillMePlease" + Name = "Test-Brooklyn-Terraform-KillMePlease" } } diff --git a/src/test/resources/state/aws-instance-state.json b/src/test/resources/state/aws-instance-state.json new file mode 100644 index 0000000..553e028 --- /dev/null +++ b/src/test/resources/state/aws-instance-state.json @@ -0,0 +1,210 @@ +{ + "format_version":"1.0", + "terraform_version":"1.2.5", + "values":{ + "root_module":{ + "resources":[ + { + "address":"aws_instance.example1", + "mode":"managed", + "type":"aws_instance", + "name":"example1", + "provider_name":"registry.terraform.io/hashicorp/aws", + "schema_version":1, + "values":{ + "ami":"ami-02df9ea15c1778c9c", + "arn":"arn:aws:ec2:eu-west-1:304295633295:instance/i-03cd093277a091c56", + "associate_public_ip_address":true, + "availability_zone":"eu-west-1c", + "capacity_reservation_specification":[ + { + "capacity_reservation_preference":"open", + "capacity_reservation_target":[ + + ] + } + ], + "cpu_core_count":1, + "cpu_threads_per_core":1, + "credit_specification":[ + + ], + "disable_api_stop":false, + "disable_api_termination":false, + "ebs_block_device":[ + + ], + "ebs_optimized":false, + "enclave_options":[ + { + "enabled":false + } + ], + "ephemeral_block_device":[ + + ], + "get_password_data":false, + "hibernation":false, + "host_id":null, + "iam_instance_profile":"", + "id":"i-03cd093277a091c56", + "instance_initiated_shutdown_behavior":"stop", + "instance_state":"running", + "instance_type":"t1.micro", + "ipv6_address_count":0, + "ipv6_addresses":[ + + ], + "key_name":"", + "launch_template":[ + + ], + "maintenance_options":[ + { + "auto_recovery":"default" + } + ], + "metadata_options":[ + { + "http_endpoint":"enabled", + "http_put_response_hop_limit":1, + "http_tokens":"optional", + "instance_metadata_tags":"disabled" + } + ], + "monitoring":false, + "network_interface":[ + + ], + "outpost_arn":"", + "password_data":"", + "placement_group":"", + "placement_partition_number":null, + "primary_network_interface_id":"eni-01d1a6df65f5ceb25", + "private_dns":"ip-172-31-29-33.eu-west-1.compute.internal", + "private_dns_name_options":[ + { + "enable_resource_name_dns_a_record":false, + "enable_resource_name_dns_aaaa_record":false, + "hostname_type":"ip-name" + } + ], + "private_ip":"172.31.29.33", + "public_dns":"ec2-3-250-116-43.eu-west-1.compute.amazonaws.com", + "public_ip":"3.250.116.43", + "root_block_device":[ + { + "delete_on_termination":true, + "device_name":"/dev/sda1", + "encrypted":false, + "iops":100, + "kms_key_id":"", + "tags":{ + + }, + "throughput":0, + "volume_id":"vol-0073ba75aa17d5544", + "volume_size":8, + "volume_type":"gp2" + } + ], + "secondary_private_ips":[ + + ], + "security_groups":[ + "default" + ], + "source_dest_check":true, + "subnet_id":"subnet-911c72e7", + "tags":{ + "Name":"Test-Brooklyn-Terraform-KillMePlease", + "Purpose":"terraform-test-cfg-in-blueprint" + }, + "tags_all":{ + "Name":"Test-Brooklyn-Terraform-KillMePlease", + "Purpose":"terraform-test-cfg-in-blueprint" + }, + "tenancy":"default", + "timeouts":null, + "user_data":null, + "user_data_base64":null, + "user_data_replace_on_change":false, + "volume_tags":null, + "vpc_security_group_ids":[ + "sg-3d20c35b" + ] + }, + "sensitive_values":{ + "capacity_reservation_specification":[ + { + "capacity_reservation_target":[ + + ] + } + ], + "credit_specification":[ + + ], + "ebs_block_device":[ + + ], + "enclave_options":[ + { + + } + ], + "ephemeral_block_device":[ + + ], + "ipv6_addresses":[ + + ], + "launch_template":[ + + ], + "maintenance_options":[ + { + + } + ], + "metadata_options":[ + { + + } + ], + "network_interface":[ + + ], + "private_dns_name_options":[ + { + + } + ], + "root_block_device":[ + { + "tags":{ + + } + } + ], + "secondary_private_ips":[ + + ], + "security_groups":[ + false + ], + "tags":{ + + }, + "tags_all":{ + + }, + "vpc_security_group_ids":[ + false + ] + } + } + ] + } + } +} \ No newline at end of file