Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloud): add availability zone filed for rds cluster #1424

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
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
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/terraform/aws/rds/adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,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.com.aquasecurity.defsec.pkg.providers.aws.rds.Cluster": {
"type": "object",
"properties": {
"availabilityzones": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/github.com.aquasecurity.defsec.pkg.types.StringValue"
}
},
"backupretentionperioddays": {
"type": "object",
"$ref": "#/definitions/github.com.aquasecurity.defsec.pkg.types.IntValue"
Expand Down