diff --git a/internal/tagging/aws.go b/internal/tagging/aws.go index ad05825..db132f4 100644 --- a/internal/tagging/aws.go +++ b/internal/tagging/aws.go @@ -9,6 +9,26 @@ import ( "github.com/hashicorp/hcl/v2/hclwrite" ) +func tagAwsInstance(args TagBlockArgs) (*Result, error) { + var swappedTagsStrings []string + + tagBlock, err := TagBlock(args) + if err != nil { + return nil, err + } + swappedTagsStrings = append(swappedTagsStrings, tagBlock) + + volumeTagBlockArgs := args + volumeTagBlockArgs.TagId = "volume_tags" + volumeTagBlock, err := TagBlock(volumeTagBlockArgs) + if err != nil { + return nil, err + } + swappedTagsStrings = append(swappedTagsStrings, volumeTagBlock) + + return &Result{SwappedTagsStrings: swappedTagsStrings}, nil +} + func tagAutoscalingGroup(args TagBlockArgs) (*Result, error) { // https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html diff --git a/internal/tagging/tagging.go b/internal/tagging/tagging.go index 3d87fbe..7dee409 100644 --- a/internal/tagging/tagging.go +++ b/internal/tagging/tagging.go @@ -69,6 +69,7 @@ func TagResource(args TagBlockArgs) (*Result, error) { var resourceTypeToFnMap = map[string]TagResourceFn{ "aws_autoscaling_group": tagAutoscalingGroup, + "aws_instance": tagAwsInstance, "google_container_cluster": tagContainerCluster, "azurerm_kubernetes_cluster": tagAksK8sCluster, } diff --git a/test/fixture/terraform_latest/config.yaml b/test/fixture/terraform_latest/config.yaml index 818259a..3ae1125 100644 --- a/test/fixture/terraform_latest/config.yaml +++ b/test/fixture/terraform_latest/config.yaml @@ -15,4 +15,5 @@ suites: - google_beta_resource_skip - google_container_cluster - google_labels_map - - google_vs_google_beta \ No newline at end of file + - google_vs_google_beta + - aws_instance_volume_tags diff --git a/test/tests/aws_instance_volume_tags/expected/main.tf b/test/tests/aws_instance_volume_tags/expected/main.tf new file mode 100644 index 0000000..8151ef6 --- /dev/null +++ b/test/tests/aws_instance_volume_tags/expected/main.tf @@ -0,0 +1,30 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 2.0" + } + } +} + +provider "aws" { + region = "us-east-1" +} + +resource "aws_instance" "ubuntu" { + ami = "dasdasD" + instance_type = "t3.micro" + availability_zone = "us-west-2" + + + tags = merge({ + "Name" = "terratag-test" + "env" = "test" + }, local.terratag_added_main) + volume_tags = local.terratag_added_main +} + +locals { + terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} +} + diff --git a/test/tests/aws_instance_volume_tags/input/main.tf b/test/tests/aws_instance_volume_tags/input/main.tf new file mode 100644 index 0000000..1fb4557 --- /dev/null +++ b/test/tests/aws_instance_volume_tags/input/main.tf @@ -0,0 +1,24 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 2.0" + } + } +} + +provider "aws" { + region = "us-east-1" +} + +resource "aws_instance" "ubuntu" { + ami = "dasdasD" + instance_type = "t3.micro" + availability_zone = "us-west-2" + + + tags = { + Name = "terratag-test" + env = "test" + } +}