Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: set volume_tags on aws_instance resource #187

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Loading