Kaguei Nakueka
Kaguei Nakueka

Reputation: 1128

Terraform - Update a newly create default route table for a VPC

How can I update the default route table that is automatically created when I create a VPC by using Terraform?

I would like to add some tags to it.

This is how I create my VPC

module "aws_vpc" {
  source = "../../modules/Virtual Private Cloud"
  vpc_cidr = "10.0.0.0/16"
  vpc_instance_tenancy = "default"
  vpc_tags = {
    Name = "Web Application VPC"
    project = "Alpha"
    cost_center = "92736"
    developer = "J.Pean"
  }
}

Module looks like this:

resource "aws_vpc" "new" {
  cidr_block = var.vpc_cidr
  instance_tenancy = "default"
  tags = var.vpc_tags
}

Upvotes: 1

Views: 1004

Answers (2)

Kaguei Nakueka
Kaguei Nakueka

Reputation: 1128

You can manage your newly created route table as well as nacl and sg through the resources:

  • aws_default_network_acl
  • aws_default_route_table
  • aws_default_security_group

Terraform documentation

Upvotes: 1

samtoddler
samtoddler

Reputation: 9655

resource "null_resource" "tag_default_route_table" {
  triggers = {
    route_table_id = aws_vpc.new.default_route_table_id
  }

  provisioner "local-exec" {
      interpreter=["/bin/bash", "-c"]
      command = <<EOF
      set -euo pipefail
      aws ec2 create-tags --resources route_table_id --tags 'Key="somekey",Value=test'
      EOF
  }
}

Using null_resource

Upvotes: 1

Related Questions