From 8751bdac2f2abc5da9c17494c68e1a2b9202af90 Mon Sep 17 00:00:00 2001 From: Elie Date: Fri, 18 Jun 2021 11:16:55 +0200 Subject: [PATCH] Fix EBS volume drift on throughput --- pkg/resource/aws/aws_ebs_volume.go | 1 + pkg/resource/aws/aws_instance_test.go | 28 +++++++++++++++ .../aws_instance_default/.terraform.lock.hcl | 21 +++++++++++ .../acc/aws_instance_default/terraform.tf | 35 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 pkg/resource/aws/testdata/acc/aws_instance_default/.terraform.lock.hcl create mode 100644 pkg/resource/aws/testdata/acc/aws_instance_default/terraform.tf diff --git a/pkg/resource/aws/aws_ebs_volume.go b/pkg/resource/aws/aws_ebs_volume.go index b7608071..3576e358 100644 --- a/pkg/resource/aws/aws_ebs_volume.go +++ b/pkg/resource/aws/aws_ebs_volume.go @@ -12,5 +12,6 @@ func initAwsEbsVolumeMetaData(resourceSchemaRepository resource.SchemaRepository val.SafeDelete([]string{"arn"}) val.SafeDelete([]string{"outpost_arn"}) val.SafeDelete([]string{"snapshot_id"}) + val.DeleteIfDefault("throughput") }) } diff --git a/pkg/resource/aws/aws_instance_test.go b/pkg/resource/aws/aws_instance_test.go index d08756aa..519d4a57 100644 --- a/pkg/resource/aws/aws_instance_test.go +++ b/pkg/resource/aws/aws_instance_test.go @@ -14,6 +14,34 @@ import ( "github.com/r3labs/diff/v2" ) +func TestAcc_AwsInstance(t *testing.T) { + acceptance.Run(t, acceptance.AccTestCase{ + TerraformVersion: "0.14.9", + Paths: []string{"./testdata/acc/aws_instance_default"}, + Args: []string{ + "scan", + "--filter", + "Type=='aws_instance' || Type=='aws_ebs_volume'", + "--tf-provider-version", + "3.45.0", + }, + Checks: []acceptance.AccCheck{ + { + Env: map[string]string{ + "AWS_REGION": "us-east-1", + }, + Check: func(result *test.ScanResult, stdout string, err error) { + if err != nil { + t.Fatal(err) + } + result.AssertInfrastructureIsInSync() + result.AssertManagedCount(2) + }, + }, + }, + }) +} + func TestAcc_AwsInstance_WithBlockDevices(t *testing.T) { var mutatedInstanceId string acceptance.Run(t, acceptance.AccTestCase{ diff --git a/pkg/resource/aws/testdata/acc/aws_instance_default/.terraform.lock.hcl b/pkg/resource/aws/testdata/acc/aws_instance_default/.terraform.lock.hcl new file mode 100644 index 00000000..c238c3f6 --- /dev/null +++ b/pkg/resource/aws/testdata/acc/aws_instance_default/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "3.45.0" + constraints = "3.45.0" + hashes = [ + "h1:LKU/xfna87/p+hl5yTTW3dvOqWJp5JEM+Dt3nnvSDvA=", + "zh:0fdbb3af75ff55807466533f97eb314556ec41a908a543d7cafb06546930f7c6", + "zh:20656895744fa0f4607096b9681c77b2385f450b1577f9151d3070818378a724", + "zh:390f316d00f25a5e45ef5410961fd05bf673068c1b701dc752d11df6d8e741d7", + "zh:3da70f9de241d5f66ea9994ef1e0beddfdb005fa2d2ef6712392f57c5d2e4844", + "zh:65de63cc0f97c85c28a19db560c546aa25f4f403dbf4783ac53c3918044cf180", + "zh:6fc52072e5a66a5d0510aaa2b373a2697895f51398613c68619d8c0c95fc75f5", + "zh:7c1da61092bd1206a020e3ee340ab11be8a4f9bb74e925ca1229ea5267fb3a62", + "zh:94e533d86ce3c08e7102dcabe34ba32ae7fd7819fd0aedef28f48d29e635eae2", + "zh:a3180d4826662e19e71cf20e925a2be8613a51f2f3f7b6d2643ac1418b976d58", + "zh:c783df364928c77fd4dec5419533b125bebe2d50212c4ad609f83b701c2d981a", + "zh:e1279bde388cb675d324584d965c6d22c3ec6890b13de76a50910a3bcd84ed64", + ] +} diff --git a/pkg/resource/aws/testdata/acc/aws_instance_default/terraform.tf b/pkg/resource/aws/testdata/acc/aws_instance_default/terraform.tf new file mode 100644 index 00000000..2194adf3 --- /dev/null +++ b/pkg/resource/aws/testdata/acc/aws_instance_default/terraform.tf @@ -0,0 +1,35 @@ +provider "aws" { + region = "us-east-1" +} +terraform { + required_providers { + aws = { + version = "3.45.0" + } + } +} + +data "aws_ami" "ubuntu" { + most_recent = true + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + owners = ["099720109477"] # Canonical +} + +resource "aws_instance" "web" { + ami = data.aws_ami.ubuntu.id + instance_type = "t3.micro" + + tags = { + Name = "HelloWorld" + } +}