CodexBloom - Programming Q&A Platform

Terraform scenarios to update AWS Security Group with 'InvalidParameterValue' scenarios during apply

πŸ‘€ Views: 2 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-03
terraform aws security-group HCL

I'm attempting to set up I've been banging my head against this for hours. This might be a silly question, but I am working with an scenario when trying to update an AWS Security Group using Terraform. The security group is configured to allow SSH access from a specific IP range, but when I try to modify the rules to add an additional IP, I receive the following behavior: `behavior: behavior applying plan: 1 behavior(s) occurred: * aws_security_group.my_sg: InvalidParameterValue: The specified rule is not valid for this resource.` I have verified that the IP addresses are correct and that there are no overlapping rules, but the behavior continues. Here’s the relevant part of my Terraform configuration: ```hcl resource "aws_security_group" "my_sg" { name_prefix = "my-security-group-" vpc_id = var.vpc_id ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["203.0.113.0/24"] } // This is the new rule I want to add ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["198.51.100.0/24"] } } ``` I’ve tried running `terraform plan` and it correctly detects the changes, but when I run `terraform apply`, I receive the invalid parameter behavior. I've also ensured that I have the latest version of the AWS provider (version 4.0.0). Additionally, I checked the AWS console and confirmed that the security group currently allows SSH access from the original CIDR block. Does anyone have experience with this kind of behavior? Any insights or suggestions would be greatly appreciated! For context: I'm using Hcl on Windows. This is part of a larger web app I'm building. Any ideas what could be causing this? Any feedback is welcome! This is part of a larger microservice I'm building. What's the correct way to implement this?