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

silent failure in cloudflare-sg module #116

Open
briskt opened this issue Oct 31, 2024 · 0 comments
Open

silent failure in cloudflare-sg module #116

briskt opened this issue Oct 31, 2024 · 0 comments

Comments

@briskt
Copy link
Contributor

briskt commented Oct 31, 2024

If the Cloudflare API used by the cloudflare-sg does not return a correct response, the data will be invalid but the Terraform plan will not necessarily fail. This is because the http provider no longer checks the return status but leaves it up to the consumer to check the new status_code attribute.

Recommendation:

Instead of using this module, use these resources directly in your module:

resource "aws_security_group" "cloudflare" {
  name        = "cloudflare"
  description = "Allow HTTPS traffic from Cloudflare"
  vpc_id      = module.vpc.id
  tags = {
    Name = "my-app-name-and-environment-cloudflare"
  }
}

resource "aws_security_group_rule" "cloudflare" {
  type              = "ingress"
  from_port         = 443
  to_port           = 443
  protocol          = "tcp"
  security_group_id = aws_security_group.cloudflare.id
  cidr_blocks       = split(",", data.external.cloudflare_ips.result.ipv4_cidrs)
  ipv6_cidr_blocks  = split(",", data.external.cloudflare_ips.result.ipv6_cidrs)
}

data "external" "cloudflare_ips" {
  program = ["${path.module}/cloudflare-ips.sh"]
}

cloudflare-ips.sh

#!/usr/bin/env bash

set -e

curl --silent --fail 'https://api.cloudflare.com/client/v4/ips' | jq '{
  ipv4_cidrs: (.result.ipv4_cidrs | join(",")),
  ipv6_cidrs: (.result.ipv6_cidrs | join(","))
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant