Skip to content

Commit f579269

Browse files
committed
check for nulls
1 parent 28820fc commit f579269

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

governance/third-generation/aws/aws-functions/aws-functions.sentinel

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -168,33 +168,37 @@ filter_resources_by_region = func(resources, region) {
168168
pck = r.provider_config_key
169169
p = tfconfig.providers[pck]
170170

171-
# First, process p itself
172-
if "config" in keys(p) and "region" in keys(p.config) {
173-
if validate_provider_region(p, region) {
174-
resources_from_region[address] = r
175-
}
176-
} else {
177-
# provider used by resource does not have region
178-
# So, we process it as an alias to a root module provider
179-
# A provider that does not have its own region should look like
180-
# <module_address>:<provider>.<alias>
181-
# we want to look at <provider>.<alias>
182-
p_segments = strings.split(p.provider_config_key, ":")
183-
if length(p_segments) == 1 {
184-
# Current provider is already in root module
185-
# So, it is not an alias to another provider
186-
# Continue on to next resource in for loop
187-
continue
188-
}
189-
# Get the provider in root module that current provider aliases
190-
p_alias_name = p_segments[1]
191-
p_alias = tfconfig.providers[p_alias_name]
192-
193-
# Process p_alias
194-
if validate_provider_region(p_alias, region) {
195-
resources_from_region[address] = r
196-
}
197-
} // end processing of p_alias
171+
# First make sure p is not null
172+
if p is not null {
173+
# First, process p itself
174+
if "config" in keys(p) and "region" in keys(p.config) {
175+
if validate_provider_region(p, region) {
176+
resources_from_region[address] = r
177+
}
178+
} else {
179+
# provider used by resource does not have region
180+
# So, we process it as an alias to a root module provider
181+
# A provider that does not have its own region should look like
182+
# <module_address>:<provider>.<alias>
183+
# we want to look at <provider>.<alias>
184+
# However, that might not exist
185+
p_segments = strings.split(p.provider_config_key, ":")
186+
if length(p_segments) == 1 {
187+
# Current provider is already in root module
188+
# So, it is not an alias to another provider
189+
# Continue on to next resource in for loop
190+
continue
191+
}
192+
# Get the provider in root module that current provider aliases
193+
p_alias_name = p_segments[1]
194+
p_alias = tfconfig.providers[p_alias_name]
195+
196+
# Process p_alias
197+
if p_alias is not null and validate_provider_region(p_alias, region) {
198+
resources_from_region[address] = r
199+
}
200+
} // end processing of p_alias
201+
} // end check p not null
198202
} // end for resources
199203

200204
return resources_from_region

0 commit comments

Comments
 (0)