Advertisement
karthikvee

dynamic-block-example

Jul 31st, 2021
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. provider "aws" {
  2. region = "us-east-1"
  3. }
  4.  
  5. locals {
  6. ingress_rules = [{
  7. port = 443
  8. description = "Ingress rules for port 443"
  9. },
  10. {
  11. port = 80
  12. description = "Ingree rules for port 80"
  13. }]
  14. }
  15.  
  16. resource "aws_vpc" "main" {
  17. cidr_block = "10.0.0.0/16"
  18. tags = {
  19. Name = "vpc-dynamic-block"
  20. }
  21. }
  22. resource "aws_security_group" "main" {
  23. name = "resource_with_dynamic_block"
  24. vpc_id = aws_vpc.main.id
  25.  
  26. dynamic "ingress" {
  27. for_each = local.ingress_rules
  28.  
  29. content {
  30. description = ingress.value.description
  31. from_port = ingress.value.port
  32. to_port = ingress.value.port
  33. protocol = "tcp"
  34. cidr_blocks = ["0.0.0.0/0"]
  35. }
  36. }
  37.  
  38. tags = {
  39. Name = "AWS security group dynamic block"
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement