Using Dynamic Blocks in Terraform

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 21

  • @harishdevarapalli1537
    @harishdevarapalli1537 3 года назад +3

    Hi Ned, thanks for your time in sharing the knowledge. How to create different volumes with different sizes using launching template through terraform and attaching to the instances created via autoscaling group?

  • @nah0221
    @nah0221 3 года назад +2

    This should be added to the official documentation !! thanks

  • @dudasamsung5115
    @dudasamsung5115 3 года назад +2

    Thanks some complex stuff described here but very thorough.

  • @omega1962
    @omega1962 2 года назад

    @ned - What if I have 2 resources groups in 2 locations, and I need to create 2 vnets and each vnet in each resource group. Will using dynamic block help my requirement, while creating vnet block, I need to iterate/loop the resource group, so that the first vnet create should make use of the first rg and the second vnet created should use the 2nd resource group?

  • @TheMyvelmurugan
    @TheMyvelmurugan Год назад

    Any inputs on the cdn endpoints delivery_rultle using dynamic block

    • @NedintheCloud
      @NedintheCloud  Год назад

      You can def use dynamic blocks with the delivery_rule nested block for azurerm_cdn_endpoint. I haven't worked much with that resource, so I can't provide much in the way of advice.

  • @jiansu
    @jiansu 2 года назад

    say i have the following code
    targets = {
    my_app1_vm1 = {
    target_id = var.private_ec2_ids[0]
    port = 80
    },
    my_app1_vm2 = {
    target_id = var.private_ec2_ids[1]
    port = 80
    }
    }
    it appears to me it can use dynamic group, or can we? because in your example, it is a map ingress {.......}
    but when it come to a assignment ingress = {} can we use dynamic group for repeating code? and How?

  • @mosksky
    @mosksky 3 года назад

    Ty Ned! can't wait for next Tue :) PS: why u keep publishing at pluralsight and not udemy there are not too many author to follow at pluralsight so that membership might not worse it. where at udemy we can selectively choose the course

  • @michaelhanley7112
    @michaelhanley7112 3 года назад

    Great Vid,
    Question how would this work with KMS keys in AWS?

    • @NedintheCloud
      @NedintheCloud  3 года назад

      Is there a particular resource type you are referencing?

    • @michaelhanley7112
      @michaelhanley7112 3 года назад

      @@NedintheCloud
      resource "aws_kms_alias" "a" {
      name = "alias/my-key-alias"
      target_key_id = aws_kms_key.a.key_id
      }.
      resource "aws_kms_key" "a" {
      description = "KMS key 1"
      deletion_window_in_days = 10
      }

    • @NedintheCloud
      @NedintheCloud  3 года назад +1

      In this case, I think you are creating multiple resources, not multiple properties in a single resource. You would create those with a for_each or count loop on the resource.
      It would be something along these lines:
      resource "aws_kms_key" "keys" {
      for_each = { kms_key_1 = "10", kms_key_2 = "10"}
      description = each.key
      deletion_window_in_days = each.value
      }
      resource "aws_kms_alias" "alias" {
      for_each = { kms_key_1 = "alias/key_1", kms_key_2 = "alias/key_2" }
      name = each.value
      target_key_id = aws_kms_key.[each.key].key_id
      }
      Although I haven't test that code, so don't quote me exactly.

  • @stefstef06
    @stefstef06 3 года назад

    Thanks Ned ! Been provisioning EC2 instances using for_each, which works, but I can't figure out yet out to reference each instance (to get its private IP address for example).
    [steph@centos7-2 02_MyFirstVPC_loop]$ terraform state list
    ...
    module.ec2["ec2_nat"].aws_instance.this[0]
    module.ec2["ec2_private"].aws_instance.this[0]
    module.ec2["ec2_public"].aws_instance.this[0]
    [steph@centos7-2 02_MyFirstVPC_loop]$ terraform state show module.ec2["ec2_nat"].aws_instance.this[0]
    Error parsing instance address: module.ec2[ec2_nat].aws_instance.this[0]
    This command requires that the address references one specific instance.
    To view the available instances, use "terraform state list". Please modify
    the address to reference a specific instance.
    [steph@centos7-2 02_MyFirstVPC_loop]$ terraform state show module.ec2["ec2_nat"]
    Error parsing instance address: module.ec2[ec2_nat]
    This command requires that the address references one specific instance.
    To view the available instances, use "terraform state list". Please modify
    the address to reference a specific instance.
    What is it that I don't understand here ? Any clue please ?

    • @stefstef06
      @stefstef06 3 года назад

      [steph@centos7-2 02_MyFirstVPC_loop]$ cat ec2.tf
      locals {
      common_tags = {
      env = var.env
      owner = var.owner
      }
      }
      locals {
      instances = jsondecode(file("ec2.json")).Instances
      }
      module "ec2" {
      source = "terraform-aws-modules/ec2-instance/aws"
      version = "~> 2.0"
      for_each = { for instance in local.instances : instance.name => instance }
      name = each.value["name"]
      instance_count = each.value["instance_count"]
      ami = each.value["ami"]
      instance_type = each.value["instance_type"]
      associate_public_ip_address = each.value["associate_public_ip_address"]
      key_name = each.value["key_name"]
      monitoring = each.value["monitoring"]
      source_dest_check = each.value["source_dest_check"]
      vpc_security_group_ids = [module.demo_sg.this_security_group_id]
      subnet_id = module.base-network.public_subnet_ids[0]
      tags = local.common_tags
      }

    • @NedintheCloud
      @NedintheCloud  3 года назад

      You should be able to reference by splatting, but you'll need to expose it as an output from the module. The syntax should be: aws_instance.RESOURCE_NAME.*.private_ip

    • @stefstef06
      @stefstef06 3 года назад

      @@NedintheCloud Thanks for your reply. I just messed up with the correct way to call for an instance created via for_each : module.ec2["ec2_nat"].private_ip
      By the way, thanks a lot for the great content you produce on your RUclips channel and on PacketPushers !

  • @HendersonHood
    @HendersonHood Год назад

    A good video but seems to be targeting those who already have an understanding of dynamic block: the examples are too complex for those trying to understand the basic concepts.

    • @NedintheCloud
      @NedintheCloud  Год назад

      I agree! This is def a more advanced topic.

  • @bernardobuffa2391
    @bernardobuffa2391 Год назад

    Terrorform rather...🤐