@@ -211,6 +211,37 @@ func (s sdk) GetSubNets(ctx context.Context, vpcID string) ([]awsResource, error
211211 return ids , nil
212212}
213213
214+ func (s sdk ) IsPublicSubnet (ctx context.Context , vpcID string , subNetID string ) (bool , error ) {
215+ tables , err := s .EC2 .DescribeRouteTablesWithContext (ctx , & ec2.DescribeRouteTablesInput {
216+ Filters : []* ec2.Filter {
217+ {
218+ Name : aws .String ("association.subnet-id" ),
219+ Values : []* string {aws .String (subNetID )},
220+ },
221+ },
222+ })
223+ if err != nil {
224+ return false , err
225+ }
226+ if len (tables .RouteTables ) == 0 {
227+ // If a subnet is not explicitly associated with any route table, it is implicitly associated with the main route table.
228+ // https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-route-tables.html
229+ return true , nil
230+ }
231+ for _ , routeTable := range tables .RouteTables {
232+ for _ , route := range routeTable .Routes {
233+ if aws .StringValue (route .State ) != "active" {
234+ continue
235+ }
236+ if strings .HasPrefix (aws .StringValue (route .GatewayId ), "igw-" ) {
237+ // Connected to an internet Gateway
238+ return true , nil
239+ }
240+ }
241+ }
242+ return false , nil
243+ }
244+
214245func (s sdk ) GetRoleArn (ctx context.Context , name string ) (string , error ) {
215246 role , err := s .IAM .GetRoleWithContext (ctx , & iam.GetRoleInput {
216247 RoleName : aws .String (name ),
0 commit comments