Skip to content

Commit 36ff306

Browse files
authored
Feat: set volume_tags on aws_instance resource (#187)
1 parent a62f048 commit 36ff306

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

internal/tagging/aws.go

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ import (
99
"github.com/hashicorp/hcl/v2/hclwrite"
1010
)
1111

12+
func tagAwsInstance(args TagBlockArgs) (*Result, error) {
13+
var swappedTagsStrings []string
14+
15+
tagBlock, err := TagBlock(args)
16+
if err != nil {
17+
return nil, err
18+
}
19+
swappedTagsStrings = append(swappedTagsStrings, tagBlock)
20+
21+
volumeTagBlockArgs := args
22+
volumeTagBlockArgs.TagId = "volume_tags"
23+
volumeTagBlock, err := TagBlock(volumeTagBlockArgs)
24+
if err != nil {
25+
return nil, err
26+
}
27+
swappedTagsStrings = append(swappedTagsStrings, volumeTagBlock)
28+
29+
return &Result{SwappedTagsStrings: swappedTagsStrings}, nil
30+
}
31+
1232
func tagAutoscalingGroup(args TagBlockArgs) (*Result, error) {
1333
// https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html
1434

internal/tagging/tagging.go

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TagResource(args TagBlockArgs) (*Result, error) {
6969

7070
var resourceTypeToFnMap = map[string]TagResourceFn{
7171
"aws_autoscaling_group": tagAutoscalingGroup,
72+
"aws_instance": tagAwsInstance,
7273
"google_container_cluster": tagContainerCluster,
7374
"azurerm_kubernetes_cluster": tagAksK8sCluster,
7475
}

test/fixture/terraform_latest/config.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ suites:
1515
- google_beta_resource_skip
1616
- google_container_cluster
1717
- google_labels_map
18-
- google_vs_google_beta
18+
- google_vs_google_beta
19+
- aws_instance_volume_tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 2.0"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
region = "us-east-1"
12+
}
13+
14+
resource "aws_instance" "ubuntu" {
15+
ami = "dasdasD"
16+
instance_type = "t3.micro"
17+
availability_zone = "us-west-2"
18+
19+
20+
tags = merge({
21+
"Name" = "terratag-test"
22+
"env" = "test"
23+
}, local.terratag_added_main)
24+
volume_tags = local.terratag_added_main
25+
}
26+
27+
locals {
28+
terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"}
29+
}
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 2.0"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
region = "us-east-1"
12+
}
13+
14+
resource "aws_instance" "ubuntu" {
15+
ami = "dasdasD"
16+
instance_type = "t3.micro"
17+
availability_zone = "us-west-2"
18+
19+
20+
tags = {
21+
Name = "terratag-test"
22+
env = "test"
23+
}
24+
}

0 commit comments

Comments
 (0)