-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mahendra Bagul <bagulm123@gmail.com>
- Loading branch information
1 parent
2e05215
commit 166c63b
Showing
56 changed files
with
2,369 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/accurics/terrascan/pkg/iac-providers/output" | ||
"github.com/accurics/terrascan/pkg/utils" | ||
) | ||
|
||
// Mapper defines the base API that each IaC provider mapper must implement. | ||
type Mapper interface { | ||
// Map transforms the provider specific template to terrascan native format. | ||
Map(doc *utils.IacDocument, params ...map[string]interface{}) (output.AllResourceConfigs, error) | ||
} |
32 changes: 32 additions & 0 deletions
32
pkg/mapper/iac-providers/cft/config/api-gateway-rest-api.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/apigateway" | ||
) | ||
|
||
// APIGatewayRestAPIConfig holds config for aws_api_gateway_rest_api | ||
type APIGatewayRestAPIConfig struct { | ||
Config | ||
EndpointConfiguration []map[string][]string `json:"endpoint_configuration"` | ||
MinimumCompressionSize int `json:"minimum_compression_size"` | ||
} | ||
|
||
// GetAPIGatewayRestAPIConfig returns config for aws_api_gateway_rest_api | ||
func GetAPIGatewayRestAPIConfig(a *apigateway.RestApi) []AWSResourceConfig { | ||
cf := APIGatewayRestAPIConfig{ | ||
Config: Config{ | ||
Name: a.Name, | ||
Tags: a.Tags, | ||
}, | ||
MinimumCompressionSize: a.MinimumCompressionSize, | ||
} | ||
// Endpoint Configuration is a []map[string][]string in terraform for some reason | ||
// despite having fixed keys and not more than one possible value | ||
ec := make(map[string][]string) | ||
if a.EndpointConfiguration != nil { | ||
ec["types"] = a.EndpointConfiguration.Types | ||
ec["vpc_endpoint_ids"] = a.EndpointConfiguration.VpcEndpointIds | ||
} | ||
cf.EndpointConfiguration = []map[string][]string{ec} | ||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/apigateway" | ||
) | ||
|
||
const ( | ||
// GatewayMethodSettings represents subresource aws_api_gateway_method_settings for MethodSettings attribute | ||
GatewayMethodSettings = "MethodSettings" | ||
) | ||
|
||
// MethodSettingConfig holds the config for aws_api_gateway_method_settings | ||
type MethodSettingConfig struct { | ||
Config | ||
MetricsEnabled bool `json:"metrics_enabled"` | ||
} | ||
|
||
// APIGatewayStageConfig holds config for aws_api_gateway_stage | ||
type APIGatewayStageConfig struct { | ||
AccessLogSettings interface{} `json:"access_log_settings"` | ||
ClientCertificateID interface{} `json:"client_certificate_id"` | ||
Config | ||
XrayTracingEnabled bool `json:"xray_tracing_enabled"` | ||
} | ||
|
||
// GetAPIGatewayStageConfig returns config for aws_api_gateway_stage and aws_api_gateway_method_settings | ||
func GetAPIGatewayStageConfig(s *apigateway.Stage) []AWSResourceConfig { | ||
|
||
resourceConfigs := make([]AWSResourceConfig, 0) | ||
|
||
cf := APIGatewayStageConfig{ | ||
Config: Config{ | ||
Name: s.StageName, | ||
Tags: s.Tags, | ||
}, | ||
} | ||
if s.AccessLogSetting != nil { | ||
cf.AccessLogSettings = s.AccessLogSetting | ||
} else { | ||
cf.AccessLogSettings = struct{}{} | ||
} | ||
cf.XrayTracingEnabled = s.TracingEnabled | ||
if len(s.ClientCertificateId) > 0 { | ||
cf.ClientCertificateID = s.ClientCertificateId | ||
} | ||
|
||
// add aws_api_gateway_stage | ||
resourceConfigs = append(resourceConfigs, AWSResourceConfig{ | ||
Resource: cf, | ||
}) | ||
|
||
// add aws_api_gateway_method_settings | ||
// multiple MethodSettings can be configured for same resource in cft | ||
if s.MethodSettings != nil { | ||
for _, settings := range s.MethodSettings { | ||
msc := make(map[string][]MethodSettingConfig) | ||
msc["settings"] = []MethodSettingConfig{{ | ||
MetricsEnabled: settings.MetricsEnabled, | ||
}} | ||
resourceConfigs = append(resourceConfigs, AWSResourceConfig{ | ||
Type: GatewayMethodSettings, | ||
Name: s.StageName, | ||
Resource: msc, | ||
}) | ||
} | ||
} | ||
|
||
return resourceConfigs | ||
} |
25 changes: 25 additions & 0 deletions
25
pkg/mapper/iac-providers/cft/config/api-gatewayv2-stage.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/apigatewayv2" | ||
) | ||
|
||
// APIGatewayV2StageConfig holds config for aws_api_gatewayv2_stage | ||
type APIGatewayV2StageConfig struct { | ||
Config | ||
AccessLogSettings interface{} `json:"access_log_settings,omitempty"` | ||
} | ||
|
||
// GetAPIGatewayV2StageConfig returns config for aws_api_gatewayv2_stage | ||
func GetAPIGatewayV2StageConfig(s *apigatewayv2.Stage) []AWSResourceConfig { | ||
cf := APIGatewayV2StageConfig{ | ||
Config: Config{ | ||
Name: s.StageName, | ||
Tags: s.Tags, | ||
}, | ||
} | ||
if s.AccessLogSettings != nil { | ||
cf.AccessLogSettings = s.AccessLogSettings | ||
} | ||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
28 changes: 28 additions & 0 deletions
28
pkg/mapper/iac-providers/cft/config/cloudformation-stack.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/cloudformation" | ||
) | ||
|
||
// CloudFormationStackConfig holds config for aws_cloudformation_stack | ||
type CloudFormationStackConfig struct { | ||
Config | ||
TemplateURL interface{} `json:"template_url"` | ||
NotificationARNs interface{} `json:"notification_arns"` | ||
} | ||
|
||
// GetCloudFormationStackConfig returns config for aws_cloudformation_stack | ||
func GetCloudFormationStackConfig(s *cloudformation.Stack) []AWSResourceConfig { | ||
cf := CloudFormationStackConfig{ | ||
Config: Config{ | ||
Tags: s.Tags, | ||
}, | ||
} | ||
if len(s.NotificationARNs) > 0 { | ||
cf.NotificationARNs = s.NotificationARNs | ||
} | ||
if len(s.TemplateURL) > 0 { | ||
cf.TemplateURL = s.TemplateURL | ||
} | ||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
74 changes: 74 additions & 0 deletions
74
pkg/mapper/iac-providers/cft/config/cloudfront-distribution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/cloudfront" | ||
) | ||
|
||
// CloudFrontDistributionConfig holds config for aws_cloudfront_distribution | ||
type CloudFrontDistributionConfig struct { | ||
Config | ||
Restrictions interface{} `json:"restrictions,omitempty"` | ||
OrderedCacheBehavior interface{} `json:"ordered_cache_behavior,omitempty"` | ||
LoggingConfig interface{} `json:"logging_config,omitempty"` | ||
ViewerCertificate interface{} `json:"viewer_certificate,omitempty"` | ||
WebACLId string `json:"web_acl_id,omitempty"` | ||
} | ||
|
||
// GetCloudFrontDistributionConfig returns config for aws_cloudfront_distribution | ||
func GetCloudFrontDistributionConfig(d *cloudfront.Distribution) []AWSResourceConfig { | ||
cf := CloudFrontDistributionConfig{ | ||
Config: Config{ | ||
Tags: d.Tags, | ||
}, | ||
} | ||
if d.DistributionConfig != nil && | ||
d.DistributionConfig.Restrictions != nil && | ||
d.DistributionConfig.Restrictions.GeoRestriction != nil && | ||
len(d.DistributionConfig.Restrictions.GeoRestriction.RestrictionType) > 0 { | ||
restrictions := make([]map[string]interface{}, 0) | ||
restriction := make(map[string]interface{}) | ||
geoRestrictions := make([]map[string]interface{}, 0) | ||
geoRestriction := make(map[string]interface{}) | ||
geoRestriction["restriction_type"] = d.DistributionConfig.Restrictions.GeoRestriction.RestrictionType | ||
if len(d.DistributionConfig.Restrictions.GeoRestriction.Locations) > 0 { | ||
geoRestriction["locations"] = d.DistributionConfig.Restrictions.GeoRestriction.Locations | ||
} | ||
geoRestrictions = append(geoRestrictions, geoRestriction) | ||
restriction["geo_restriction"] = geoRestrictions | ||
restrictions = append(restrictions, restriction) | ||
if len(restrictions) > 0 { | ||
cf.Restrictions = restrictions | ||
} | ||
} | ||
if d.DistributionConfig.CacheBehaviors != nil { | ||
orderedCacheBehaviors := make([]map[string]interface{}, 0) | ||
for i := range d.DistributionConfig.CacheBehaviors { | ||
orderedCacheBehavior := make(map[string]interface{}) | ||
orderedCacheBehavior["viewer_protocol_policy"] = d.DistributionConfig.CacheBehaviors[i].ViewerProtocolPolicy | ||
orderedCacheBehaviors = append(orderedCacheBehaviors, orderedCacheBehavior) | ||
} | ||
if len(orderedCacheBehaviors) > 0 { | ||
cf.OrderedCacheBehavior = orderedCacheBehaviors | ||
} | ||
} | ||
if d.DistributionConfig.Logging != nil { | ||
loggingConfigs := make([]interface{}, 0) | ||
loggingConfigs = append(loggingConfigs, d.DistributionConfig.Logging) | ||
if len(loggingConfigs) > 0 { | ||
cf.LoggingConfig = loggingConfigs | ||
} | ||
} | ||
if d.DistributionConfig.ViewerCertificate != nil { | ||
viewerCertificates := make([]map[string]interface{}, 0) | ||
viewerCertificate := make(map[string]interface{}) | ||
viewerCertificate["cloudfront_default_certificate"] = d.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate | ||
viewerCertificate["minimum_protocol_version"] = d.DistributionConfig.ViewerCertificate.MinimumProtocolVersion | ||
viewerCertificates = append(viewerCertificates, viewerCertificate) | ||
if len(viewerCertificates) > 0 { | ||
cf.ViewerCertificate = viewerCertificates | ||
} | ||
} | ||
cf.WebACLId = d.DistributionConfig.WebACLId | ||
|
||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/cloudtrail" | ||
) | ||
|
||
// CloudTrailConfig holds config for aws_cloudtrail | ||
type CloudTrailConfig struct { | ||
Config | ||
IsMultiRegionTrail interface{} `json:"is_multi_region_trail"` | ||
KmsKeyID interface{} `json:"kms_key_id"` | ||
SnsTopicName interface{} `json:"sns_topic_name"` | ||
EnableLogFileValidation interface{} `json:"enable_log_file_validation"` | ||
} | ||
|
||
// GetCloudTrailConfig returns config for aws_cloudtrail | ||
func GetCloudTrailConfig(t *cloudtrail.Trail) []AWSResourceConfig { | ||
cf := CloudTrailConfig{ | ||
Config: Config{Tags: t.Tags, Name: t.TrailName}, | ||
EnableLogFileValidation: t.EnableLogFileValidation, | ||
IsMultiRegionTrail: t.IsMultiRegionTrail, | ||
} | ||
if len(t.KMSKeyId) > 0 { | ||
cf.KmsKeyID = t.KMSKeyId | ||
} | ||
if len(t.SnsTopicName) > 0 { | ||
cf.SnsTopicName = t.SnsTopicName | ||
} | ||
|
||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
26 changes: 26 additions & 0 deletions
26
pkg/mapper/iac-providers/cft/config/cloudwatch-log-group.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/logs" | ||
) | ||
|
||
// LogCloudWatchGroupConfig holds config for aws_cloudwatch_log_group | ||
type LogCloudWatchGroupConfig struct { | ||
Config | ||
LogGroupName string `json:"name"` | ||
KmsKeyID string `json:"kms_key_id,omitempty"` | ||
RetentionInDays int `json:"retention_in_days"` | ||
} | ||
|
||
// GetLogCloudWatchGroupConfig returns config for aws_cloudwatch_log_group | ||
func GetLogCloudWatchGroupConfig(r *logs.LogGroup) []AWSResourceConfig { | ||
cf := LogCloudWatchGroupConfig{ | ||
Config: Config{ | ||
Name: r.LogGroupName, | ||
}, | ||
LogGroupName: r.LogGroupName, | ||
KmsKeyID: r.KmsKeyId, | ||
RetentionInDays: r.RetentionInDays, | ||
} | ||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/awslabs/goformation/v4/cloudformation/config" | ||
) | ||
|
||
// AWSConfigConfigRuleConfig holds config for aws_config_config_rule | ||
type AWSConfigConfigRuleConfig struct { | ||
Config | ||
Source interface{} `json:"source"` | ||
} | ||
|
||
// GetConfigConfigRuleConfig returns config for aws_config_config_rule | ||
func GetConfigConfigRuleConfig(c *config.ConfigRule) []AWSResourceConfig { | ||
cf := AWSConfigConfigRuleConfig{ | ||
Config: Config{Name: c.ConfigRuleName}, | ||
} | ||
if c.Source != nil { | ||
sources := make([]map[string]interface{}, 0) | ||
source := make(map[string]interface{}) | ||
source["source_identifier"] = c.Source.SourceIdentifier | ||
sources = append(sources, source) | ||
if len(sources) > 0 { | ||
cf.Source = sources | ||
} | ||
} | ||
|
||
return []AWSResourceConfig{{Resource: cf}} | ||
} |
Oops, something went wrong.