Skip to content

Commit

Permalink
feat(cloud): add availability zone for rds cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
int-tt authored and simar7 committed Aug 18, 2023
1 parent 8037ce0 commit eb205a0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/adapters/cloud/aws/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ func (a *adapter) adaptCluster(dbCluster types.DBCluster) (*rds.Cluster, error)
engine = *dbCluster.Engine
}

var availabilityZones []defsecTypes.StringValue
for _, az := range dbCluster.AvailabilityZones {
availabilityZones = append(availabilityZones, defsecTypes.String(az, dbClusterMetadata))
}

cluster := &rds.Cluster{
Metadata: dbClusterMetadata,
BackupRetentionPeriodDays: defsecTypes.IntFromInt32(aws.ToInt32(dbCluster.BackupRetentionPeriod), dbClusterMetadata),
Expand All @@ -261,6 +266,7 @@ func (a *adapter) adaptCluster(dbCluster types.DBCluster) (*rds.Cluster, error)
PublicAccess: defsecTypes.Bool(aws.ToBool(dbCluster.PubliclyAccessible), dbClusterMetadata),
Engine: defsecTypes.String(engine, dbClusterMetadata),
LatestRestorableTime: defsecTypes.TimeUnresolvable(dbClusterMetadata),
AvailabilityZones: availabilityZones,
}

return cluster, nil
Expand Down
1 change: 1 addition & 0 deletions internal/adapters/cloudformation/aws/rds/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func getClusters(ctx parser.FileContext) (clusters map[string]rds.Cluster) {
PublicAccess: defsecTypes.BoolDefault(false, clusterResource.Metadata()),
Engine: defsecTypes.StringDefault(rds.EngineAurora, clusterResource.Metadata()),
LatestRestorableTime: defsecTypes.TimeUnresolvable(clusterResource.Metadata()),
AvailabilityZones: nil,
}

if engineProp := clusterResource.GetProperty("Engine"); engineProp.IsString() {
Expand Down
2 changes: 2 additions & 0 deletions internal/adapters/terraform/aws/rds/adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func getClusters(modules terraform.Modules) (clusters []rds.Cluster) {
PublicAccess: defsecTypes.BoolDefault(false, defsecTypes.NewUnmanagedMetadata()),
Engine: defsecTypes.StringUnresolvable(defsecTypes.NewUnmanagedMetadata()),
LatestRestorableTime: defsecTypes.TimeUnresolvable(defsecTypes.NewUnmanagedMetadata()),
AvailabilityZones: nil,
}
for _, orphan := range orphanResources {
orphanage.Instances = append(orphanage.Instances, adaptClusterInstance(orphan, modules))
Expand Down Expand Up @@ -223,6 +224,7 @@ func adaptCluster(resource *terraform.Block, modules terraform.Modules) (rds.Clu
PublicAccess: defsecTypes.Bool(public, resource.GetMetadata()),
Engine: resource.GetAttribute("engine").AsStringValueOrDefault(rds.EngineAurora, resource),
LatestRestorableTime: defsecTypes.TimeUnresolvable(resource.GetMetadata()),
AvailabilityZones: resource.GetAttribute("availability_zones").AsStringValueSliceOrEmpty(resource),
}, ids
}

Expand Down
6 changes: 6 additions & 0 deletions internal/adapters/terraform/aws/rds/adapt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Test_Adapt(t *testing.T) {
resource "aws_rds_cluster" "example" {
engine = "aurora-mysql"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
backup_retention_period = 7
kms_key_id = "kms_key_1"
storage_encrypted = true
Expand Down Expand Up @@ -115,6 +116,11 @@ func Test_Adapt(t *testing.T) {
},
PublicAccess: defsecTypes.Bool(false, defsecTypes.NewTestMetadata()),
Engine: defsecTypes.String(rds.EngineAuroraMysql, defsecTypes.NewTestMetadata()),
AvailabilityZones: defsecTypes.StringValueList{
defsecTypes.String("us-west-2a", defsecTypes.NewTestMetadata()),
defsecTypes.String("us-west-2b", defsecTypes.NewTestMetadata()),
defsecTypes.String("us-west-2c", defsecTypes.NewTestMetadata()),
},
},
},
Classic: rds.Classic{
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/aws/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Cluster struct {
PublicAccess defsecTypes.BoolValue
Engine defsecTypes.StringValue
LatestRestorableTime defsecTypes.TimeValue
AvailabilityZones []defsecTypes.StringValue
}

type Snapshots struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/rego/schemas/cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,13 @@
"github.aaakk.us.kg.aquasecurity.defsec.pkg.providers.aws.rds.Cluster": {
"type": "object",
"properties": {
"availabilityzones": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/github.aaakk.us.kg.aquasecurity.defsec.pkg.types.StringValue"
}
},
"backupretentionperioddays": {
"type": "object",
"$ref": "#/definitions/github.aaakk.us.kg.aquasecurity.defsec.pkg.types.IntValue"
Expand Down

0 comments on commit eb205a0

Please sign in to comment.