Skip to content

Commit

Permalink
Feat: set volume_tags on aws_instance resource (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Feb 15, 2024
1 parent a62f048 commit 36ff306
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
20 changes: 20 additions & 0 deletions internal/tagging/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions internal/tagging/tagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/terraform_latest/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ suites:
- google_beta_resource_skip
- google_container_cluster
- google_labels_map
- google_vs_google_beta
- google_vs_google_beta
- aws_instance_volume_tags
30 changes: 30 additions & 0 deletions test/tests/aws_instance_volume_tags/expected/main.tf
Original file line number Diff line number Diff line change
@@ -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"}
}

24 changes: 24 additions & 0 deletions test/tests/aws_instance_volume_tags/input/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 36ff306

Please sign in to comment.