Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions internal/service/apigateway/apigateway_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,17 @@ func (s *ApigatewayGatewayResourceCrud) Create() error {
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
}

if networkSecurityGroupIds, ok := s.D.GetOkExists("network_security_group_ids"); ok {
set := networkSecurityGroupIds.(*schema.Set)
// Always set network security group IDs if provided, even if empty.
if v, ok := s.D.GetOk("network_security_group_ids"); ok {
set := v.(*schema.Set)
interfaces := set.List()
tmp := make([]string, len(interfaces))
for i := range interfaces {
if interfaces[i] != nil {
tmp[i] = interfaces[i].(string)
}
}
if len(tmp) != 0 || s.D.HasChange("network_security_group_ids") {
request.NetworkSecurityGroupIds = tmp
}
request.NetworkSecurityGroupIds = tmp
}

if responseCacheDetails, ok := s.D.GetOkExists("response_cache_details"); ok {
Expand Down Expand Up @@ -611,18 +610,17 @@ func (s *ApigatewayGatewayResourceCrud) Update() error {
tmp := s.D.Id()
request.GatewayId = &tmp

if networkSecurityGroupIds, ok := s.D.GetOkExists("network_security_group_ids"); ok {
set := networkSecurityGroupIds.(*schema.Set)
// Always update the network security group IDs if there is a change—even when removing all NSGs.
if s.D.HasChange("network_security_group_ids") {
set := s.D.Get("network_security_group_ids").(*schema.Set)
interfaces := set.List()
tmp := make([]string, len(interfaces))
for i := range interfaces {
if interfaces[i] != nil {
tmp[i] = interfaces[i].(string)
}
}
if len(tmp) != 0 || s.D.HasChange("network_security_group_ids") {
request.NetworkSecurityGroupIds = tmp
}
request.NetworkSecurityGroupIds = tmp
}

if responseCacheDetails, ok := s.D.GetOkExists("response_cache_details"); ok {
Expand Down