AWS Security group rules delete existing rules

I have a terraform script creating Security group and security group rules , this script is provided by the product , cannot edit , if i have to write a script to update security group rules how can i do in another script.

In AWS you can do as follows:

Option 1: :heavy_plus_sign: Aggregate security rules

Instead of modifying the existing security group let it alone (not managed by your controlled Terraform).

In your managed Terraform Create a NEW security group and assign it to the same infrastructure elements that the existing security group is assigned.

Rules will be evaluated taking into account both security rules.

"When you associate multiple security groups with an instance, the rules from each security group are effectively aggregated to create one set of rules. Amazon EC2 uses this set of rules to determine whether to allow access. " see:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html

Option 2: :warning: Use a data source
Use a Data Source to get IDs of the existing Security Group and change it. I don’t like this option because you could end up loosing the changes if the first Terraform (the one you don’t control) executes again.
See: