github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/client/aws_api.go (about)

     1  package client
     2  
     3  import (
     4  	"github.com/aws/aws-sdk-go/service/ec2"
     5  	"github.com/aws/aws-sdk-go/service/elasticache"
     6  	"github.com/aws/aws-sdk-go/service/iam"
     7  	"github.com/aws/aws-sdk-go/service/rds"
     8  )
     9  
    10  // DescribeSecurityGroups is a wrapper of DescribeSecurityGroups
    11  func (c *AwsClient) DescribeSecurityGroups() (map[string]bool, error) {
    12  	ret := map[string]bool{}
    13  	resp, err := c.EC2.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{})
    14  	if err != nil {
    15  		return ret, err
    16  	}
    17  	for _, sg := range resp.SecurityGroups {
    18  		ret[*sg.GroupId] = true
    19  	}
    20  	return ret, err
    21  }
    22  
    23  // DescribeSubnets is a wrapper of DescribeSubnets
    24  func (c *AwsClient) DescribeSubnets() (map[string]bool, error) {
    25  	ret := map[string]bool{}
    26  	resp, err := c.EC2.DescribeSubnets(&ec2.DescribeSubnetsInput{})
    27  	if err != nil {
    28  		return ret, err
    29  	}
    30  	for _, subnet := range resp.Subnets {
    31  		ret[*subnet.SubnetId] = true
    32  	}
    33  	return ret, err
    34  }
    35  
    36  // DescribeDBSubnetGroups is a wrapper of DescribeDBSubnetGroups
    37  func (c *AwsClient) DescribeDBSubnetGroups() (map[string]bool, error) {
    38  	ret := map[string]bool{}
    39  	resp, err := c.RDS.DescribeDBSubnetGroups(&rds.DescribeDBSubnetGroupsInput{})
    40  	if err != nil {
    41  		return ret, err
    42  	}
    43  	for _, subnetGroup := range resp.DBSubnetGroups {
    44  		ret[*subnetGroup.DBSubnetGroupName] = true
    45  	}
    46  	return ret, err
    47  }
    48  
    49  // DescribeOptionGroups is a wrapper of DescribeOptionGroups
    50  func (c *AwsClient) DescribeOptionGroups() (map[string]bool, error) {
    51  	ret := map[string]bool{}
    52  	resp, err := c.RDS.DescribeOptionGroups(&rds.DescribeOptionGroupsInput{})
    53  	if err != nil {
    54  		return ret, err
    55  	}
    56  	for _, optionGroup := range resp.OptionGroupsList {
    57  		ret[*optionGroup.OptionGroupName] = true
    58  	}
    59  	return ret, err
    60  }
    61  
    62  // DescribeDBParameterGroups is a wrapper of DescribeDBParameterGroups
    63  func (c *AwsClient) DescribeDBParameterGroups() (map[string]bool, error) {
    64  	ret := map[string]bool{}
    65  	resp, err := c.RDS.DescribeDBParameterGroups(&rds.DescribeDBParameterGroupsInput{})
    66  	if err != nil {
    67  		return ret, err
    68  	}
    69  	for _, parameterGroup := range resp.DBParameterGroups {
    70  		ret[*parameterGroup.DBParameterGroupName] = true
    71  	}
    72  	return ret, err
    73  }
    74  
    75  // DescribeCacheParameterGroups is a wrapper of DescribeCacheParameterGroups
    76  func (c *AwsClient) DescribeCacheParameterGroups() (map[string]bool, error) {
    77  	ret := map[string]bool{}
    78  	resp, err := c.ElastiCache.DescribeCacheParameterGroups(&elasticache.DescribeCacheParameterGroupsInput{})
    79  	if err != nil {
    80  		return ret, err
    81  	}
    82  	for _, parameterGroup := range resp.CacheParameterGroups {
    83  		ret[*parameterGroup.CacheParameterGroupName] = true
    84  	}
    85  	return ret, err
    86  }
    87  
    88  // DescribeCacheSubnetGroups is a wrapper of DescribeCacheSubnetGroups
    89  func (c *AwsClient) DescribeCacheSubnetGroups() (map[string]bool, error) {
    90  	ret := map[string]bool{}
    91  	resp, err := c.ElastiCache.DescribeCacheSubnetGroups(&elasticache.DescribeCacheSubnetGroupsInput{})
    92  	if err != nil {
    93  		return ret, err
    94  	}
    95  	for _, subnetGroup := range resp.CacheSubnetGroups {
    96  		ret[*subnetGroup.CacheSubnetGroupName] = true
    97  	}
    98  	return ret, err
    99  }
   100  
   101  // DescribeInstances is a wrapper of DescribeInstances
   102  func (c *AwsClient) DescribeInstances() (map[string]bool, error) {
   103  	ret := map[string]bool{}
   104  	resp, err := c.EC2.DescribeInstances(&ec2.DescribeInstancesInput{})
   105  	if err != nil {
   106  		return ret, err
   107  	}
   108  	for _, reservation := range resp.Reservations {
   109  		for _, instance := range reservation.Instances {
   110  			ret[*instance.InstanceId] = true
   111  		}
   112  	}
   113  	return ret, err
   114  }
   115  
   116  // ListInstanceProfiles is a wrapper of ListInstanceProfiles
   117  func (c *AwsClient) ListInstanceProfiles() (map[string]bool, error) {
   118  	ret := map[string]bool{}
   119  	resp, err := c.IAM.ListInstanceProfiles(&iam.ListInstanceProfilesInput{})
   120  	if err != nil {
   121  		return ret, err
   122  	}
   123  	for _, iamProfile := range resp.InstanceProfiles {
   124  		ret[*iamProfile.InstanceProfileName] = true
   125  	}
   126  	return ret, err
   127  }
   128  
   129  // DescribeKeyPairs is a wrapper of DescribeKeyPairs
   130  func (c *AwsClient) DescribeKeyPairs() (map[string]bool, error) {
   131  	ret := map[string]bool{}
   132  	resp, err := c.EC2.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{})
   133  	if err != nil {
   134  		return ret, err
   135  	}
   136  	for _, keyPair := range resp.KeyPairs {
   137  		ret[*keyPair.KeyName] = true
   138  	}
   139  	return ret, err
   140  }
   141  
   142  // DescribeEgressOnlyInternetGateways is wrapper of DescribeEgressOnlyInternetGateways
   143  func (c *AwsClient) DescribeEgressOnlyInternetGateways() (map[string]bool, error) {
   144  	ret := map[string]bool{}
   145  	resp, err := c.EC2.DescribeEgressOnlyInternetGateways(&ec2.DescribeEgressOnlyInternetGatewaysInput{})
   146  	if err != nil {
   147  		return ret, err
   148  	}
   149  	for _, egateway := range resp.EgressOnlyInternetGateways {
   150  		ret[*egateway.EgressOnlyInternetGatewayId] = true
   151  	}
   152  	return ret, err
   153  }
   154  
   155  // DescribeInternetGateways is a wrapper of DescribeInternetGateways
   156  func (c *AwsClient) DescribeInternetGateways() (map[string]bool, error) {
   157  	ret := map[string]bool{}
   158  	resp, err := c.EC2.DescribeInternetGateways(&ec2.DescribeInternetGatewaysInput{})
   159  	if err != nil {
   160  		return ret, err
   161  	}
   162  	for _, gateway := range resp.InternetGateways {
   163  		ret[*gateway.InternetGatewayId] = true
   164  	}
   165  	return ret, err
   166  }
   167  
   168  // DescribeNatGateways is a wrapper of DescribeNatGateways
   169  func (c *AwsClient) DescribeNatGateways() (map[string]bool, error) {
   170  	ret := map[string]bool{}
   171  	resp, err := c.EC2.DescribeNatGateways(&ec2.DescribeNatGatewaysInput{})
   172  	if err != nil {
   173  		return ret, err
   174  	}
   175  	for _, ngateway := range resp.NatGateways {
   176  		ret[*ngateway.NatGatewayId] = true
   177  	}
   178  	return ret, err
   179  }
   180  
   181  // DescribeNetworkInterfaces is a wrapper of DescribeNetworkInterfaces
   182  func (c *AwsClient) DescribeNetworkInterfaces() (map[string]bool, error) {
   183  	ret := map[string]bool{}
   184  	resp, err := c.EC2.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{})
   185  	if err != nil {
   186  		return ret, err
   187  	}
   188  	for _, networkInterface := range resp.NetworkInterfaces {
   189  		ret[*networkInterface.NetworkInterfaceId] = true
   190  	}
   191  	return ret, err
   192  }
   193  
   194  // DescribeRouteTables is a wrapper of DescribeRouteTables
   195  func (c *AwsClient) DescribeRouteTables() (map[string]bool, error) {
   196  	ret := map[string]bool{}
   197  	resp, err := c.EC2.DescribeRouteTables(&ec2.DescribeRouteTablesInput{})
   198  	if err != nil {
   199  		return ret, err
   200  	}
   201  	for _, routeTable := range resp.RouteTables {
   202  		ret[*routeTable.RouteTableId] = true
   203  	}
   204  	return ret, err
   205  }
   206  
   207  // DescribeVpcPeeringConnections is a wrapper of DescribeVpcPeeringConnections
   208  func (c *AwsClient) DescribeVpcPeeringConnections() (map[string]bool, error) {
   209  	ret := map[string]bool{}
   210  	resp, err := c.EC2.DescribeVpcPeeringConnections(&ec2.DescribeVpcPeeringConnectionsInput{})
   211  	if err != nil {
   212  		return ret, err
   213  	}
   214  	for _, vpcPeeringConnection := range resp.VpcPeeringConnections {
   215  		ret[*vpcPeeringConnection.VpcPeeringConnectionId] = true
   216  	}
   217  	return ret, err
   218  }