Skip to content

Commit

Permalink
MM-52337: Use aws_opensearch_domain (#701)
Browse files Browse the repository at this point in the history
* Bump aws provider version

The previous version, 3.0, did not support aws_opensearch_domain
resource, so we bumped it to the latest one.

In turn, the latest version, 5.39 does not support aws_subnet_ids, which
was replaced with aws_subnets.

* Update Terraform lock file

This is done running terraform init -upgrade inside the
deployment/terraform/assets directory.

* Replace elasticsearch resource with opensearch

The version is now specified in the engine_version field, not in the
elasticsearch_version field. This field is now a string instead of a
number.

* make assets

* Add validation for ElasticSearchSettings.Version

* Document ElasticSearch's InstanceType and Version

* Fix tags
  • Loading branch information
agarciamontoro authored Mar 6, 2024
1 parent e1fdc14 commit f0d71f9
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 43 deletions.
4 changes: 2 additions & 2 deletions config/deployer.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"AgentInstanceType": "c5.xlarge",
"ElasticSearchSettings": {
"InstanceCount": 0,
"InstanceType": "r5.large.elasticsearch",
"InstanceType": "r6g.large.search",
"VpcID": "",
"Version": 6.5,
"Version": "Elasticsearch_7.10",
"CreateRole": false
},
"JobServerSettings":{
Expand Down
22 changes: 18 additions & 4 deletions defaults/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
)

var (
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
rangeRegex = regexp.MustCompile(`range:(\[|\()(\S*)\,(\S*)(\]|\))`)
oneofRegex = regexp.MustCompile(`oneof:(\{)(.*)(\})`)
eachRegex = regexp.MustCompile(`each:(.+)`)
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
rangeRegex = regexp.MustCompile(`range:(\[|\()(\S*)\,(\S*)(\]|\))`)
oneofRegex = regexp.MustCompile(`oneof:(\{)(.*)(\})`)
eachRegex = regexp.MustCompile(`each:(.+)`)
prefixRegex = regexp.MustCompile(`prefix:(.+)`)
)

// Validate validates each field of the value
Expand Down Expand Up @@ -184,6 +185,19 @@ func validate(validation, fieldName string, p, v reflect.Value) error {
return err
}
}
} else if strings.HasPrefix(validation, "prefix") {
if !prefixRegex.MatchString(validation) {
return fmt.Errorf("invalid prefix declaration")
}
kind := v.Kind()
if kind != reflect.String {
return fmt.Errorf("validation 'prefix' can only be applied to strings, but the type of this value is %s", kind.String())
}
prefix := prefixRegex.FindStringSubmatch(validation)[1]
value := v.String()
if !strings.HasPrefix(value, prefix) {
return fmt.Errorf("value %q is not prefixed by %q", value, prefix)
}
} else {
return fmt.Errorf("validation type %q unknown", validation)
}
Expand Down
52 changes: 52 additions & 0 deletions defaults/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,58 @@ func TestValidate(t *testing.T) {
})

})

t.Run("prefix validation", func(t *testing.T) {
type cfg struct {
PrefixedValue string `validate:"prefix:start"`
}

cases := []struct {
name string
prefix string
expectedErr bool
}{
{
"just the prefix",
"start",
false,
},
{
"prefix and more stuff",
"starting",
false,
},
{
"different casing",
"StarT",
true,
},
{
"different prefix",
"nostart",
true,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := Validate(cfg{tc.prefix})
if tc.expectedErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
})

t.Run("wrong prefix tag", func(t *testing.T) {
type cfg struct {
PrefixedValue string `validate:"prefixasdf:start"`
}
err := Validate(cfg{"start"})
require.Error(t, err)
})
}

type testConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type ElasticSearchSettings struct {
// Elasticsearch instance type to be created.
InstanceType string
// Elasticsearch version to be deployed.
Version float64
Version string `default:"Elasticsearch_7.10" validate:"prefix:Elasticsearch_"`
// Id of the VPC associated with the instance to be created.
VpcID string
// Set to true if the AWSServiceRoleForAmazonElasticsearchService role should be created.
Expand Down
88 changes: 74 additions & 14 deletions deployment/terraform/assets/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0d71f9

Please sign in to comment.