Skip to content

Commit

Permalink
Merge pull request #13 from silvercar/sg-template-update
Browse files Browse the repository at this point in the history
Updating security group id reference
  • Loading branch information
kenske authored May 13, 2020
2 parents 14228d8 + 0d42b93 commit d80a02e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/terrafort/resources/aws_security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def render(self, commands=False):
group = response['SecurityGroups'][0]

output = renderer.render(group, sg_template)
group_id = "${aws_security_group.%s.id}" % group['GroupName']
group_id = "aws_security_group.%s.id" % group['GroupName']

renderer.reset_count() # Need this to add a numeric suffix to each rule name
for permission in group['IpPermissions']:
Expand Down
10 changes: 4 additions & 6 deletions src/terrafort/templates/aws_security_group_rule.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% for range in resource.IpRanges %}
{% set rule_num = count() %}
resource "aws_security_group_rule" "{{ resource.name }}{% if rule_num > 0 %}-{{ rule_num }}{% endif %}" {
resource "aws_security_group_rule" "{{ resource.name }}{% if rule_num > 0 %}_{{ rule_num }}{% endif %}" {
security_group_id = "{{ resource.id }}"
type = "{{ resource.type }}"
from_port = {{ resource.FromPort | default('0')}}
Expand All @@ -9,19 +9,17 @@ resource "aws_security_group_rule" "{{ resource.name }}{% if rule_num > 0 %}-{{
cidr_blocks = ["{{ range.CidrIp }}"]
description = "{{ range.Description }}"
}

{% endfor %}

{% for source in resource.UserIdGroupPairs %}
{% set rule_num = count() %}
resource "aws_security_group_rule" "{{ resource.name }}{% if rule_num > 0 %}-{{ rule_num }}{% endif %}" {
resource "aws_security_group_rule" "{{ resource.name }}{% if rule_num > 0 %}_{{ rule_num }}{% endif %}" {
security_group_id = "{{ resource.id }}"
type = "{{ resource.type }}"
from_port = {{resource.FromPort | default('0')}}
to_port = {{resource.ToPort| default('0')}}
from_port = {{ resource.FromPort | default('0') }}
to_port = {{ resource.ToPort | default('0') }}
protocol = "{{ resource.IpProtocol}}"
source_security_group_id = "{{ source.GroupId }}"
description = "{{ source.Description }}"
}

{% endfor %}

0 comments on commit d80a02e

Please sign in to comment.