Skip to content

Commit

Permalink
fix(cloudformation): resolve DedicatedMasterEnabled parsing issue (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin authored and fl0pp5 committed May 6, 2024
1 parent af91535 commit 721d4eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/iac/adapters/cloudformation/aws/elasticsearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ func getDomains(ctx parser.FileContext) (domains []elasticsearch.Domain) {
Metadata: r.Metadata(),
DomainName: r.GetStringProperty("DomainName"),
AccessPolicies: r.GetStringProperty("AccessPolicies"),
// TODO: ElasticsearchClusterConfig changed to ClusterConfig
DedicatedMasterEnabled: r.GetBoolProperty("ElasticsearchClusterConfig.DedicatedMasterEnabled"),
VpcId: iacTypes.String("", r.Metadata()),
VpcId: iacTypes.String("", r.Metadata()),
LogPublishing: elasticsearch.LogPublishing{
Metadata: r.Metadata(),
AuditEnabled: iacTypes.BoolDefault(false, r.Metadata()),
Expand Down Expand Up @@ -46,6 +44,12 @@ func getDomains(ctx parser.FileContext) (domains []elasticsearch.Domain) {
},
}

if r.Type() == "AWS::OpenSearchService::Domain" {
domain.DedicatedMasterEnabled = r.GetBoolProperty("ClusterConfig.DedicatedMasterEnabled")
} else {
domain.DedicatedMasterEnabled = r.GetBoolProperty("ElasticsearchClusterConfig.DedicatedMasterEnabled")
}

if prop := r.GetProperty("LogPublishingOptions"); prop.IsNotNil() {
domain.LogPublishing = elasticsearch.LogPublishing{
Metadata: prop.Metadata(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Resources:
Type: AWS::OpenSearchService::Domain
Properties:
DomainName: 'test'
ClusterConfig:
DedicatedMasterEnabled: true
NodeToNodeEncryptionOptions:
Enabled: true
EncryptionAtRestOptions:
Expand All @@ -47,7 +49,8 @@ Resources:
expected: elasticsearch.Elasticsearch{
Domains: []elasticsearch.Domain{
{
DomainName: types.StringTest("test"),
DomainName: types.StringTest("test"),
DedicatedMasterEnabled: types.BoolTest(true),
LogPublishing: elasticsearch.LogPublishing{
AuditEnabled: types.BoolTest(true),
CloudWatchLogGroupArn: types.StringTest("arn:aws:logs:us-east-1:123456789012:log-group:/aws/opensearch/domains/opensearch-application-logs"),
Expand Down Expand Up @@ -78,6 +81,24 @@ Resources:
Domains: []elasticsearch.Domain{{}},
},
},
{
name: "Elasticsearch",
source: `AWSTemplateFormatVersion: 2010-09-09
Resources:
ElasticsearchDomain:
Type: AWS::Elasticsearch::Domain
Properties:
ElasticsearchClusterConfig:
DedicatedMasterEnabled: true
`,
expected: elasticsearch.Elasticsearch{
Domains: []elasticsearch.Domain{
{
DedicatedMasterEnabled: types.BoolTest(true),
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 721d4eb

Please sign in to comment.