Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into MM-60675
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 committed Sep 26, 2024
2 parents 3d7332c + aa5b00f commit a957878
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/deployer.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@
"EnableAppProfiling": true,
"EnableAgentProfiling": true,
"BlockProfileRate": 0
},
"CustomTags": {
}
}
2 changes: 2 additions & 0 deletions config/deployer.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ InstanceEngine = 'aurora-postgresql'
InstanceType = 'db.r6g.large'
Password = 'mostest80098bigpass_'
UserName = 'mmuser'

[CustomTags]
15 changes: 15 additions & 0 deletions deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ type Config struct {
StorageSizes StorageSizes
// EnableNetPeekMetrics enables fine grained networking metrics collection through netpeek utility.
EnableNetPeekMetrics bool `default:"false"`
// CustomTags is an optional list of key-value pairs, which will be used as default
// tags for all resources deployed
CustomTags TerraformMap
}

// TerraformMap is a map of string -> string that serializes to the format expected by
// the Terraform AWS provider when formatted as a string
type TerraformMap map[string]string

func (t TerraformMap) String() string {
var pairs []string
for key, value := range t {
pairs = append(pairs, fmt.Sprintf("%s = %q", key, value))
}
return "{" + strings.Join(pairs, ", ") + "}"
}

type StorageSizes struct {
Expand Down
37 changes: 37 additions & 0 deletions deployment/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,40 @@ func TestValidateElasticSearchConfig(t *testing.T) {
require.NoError(t, cfg.validateElasticSearchConfig())
})
}

func TestTerraformMapString(t *testing.T) {
var nilMap TerraformMap
emptyMap := make(TerraformMap)

testCases := []struct {
actual TerraformMap
expected string
}{
{
actual: TerraformMap{
"uno": "1",
},
expected: "{uno = \"1\"}",
},
{
actual: TerraformMap{
"uno": "1",
"dos": "2",
},
expected: "{uno = \"1\", dos = \"2\"}",
},
{
actual: nilMap,
expected: "{}",
},
{
actual: emptyMap,
expected: "{}",
},
}

for _, testCase := range testCases {
require.Equal(t, testCase.expected, testCase.actual.String())
}

}
12 changes: 6 additions & 6 deletions deployment/terraform/assets/bindata.go

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions deployment/terraform/assets/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ provider "aws" {
region = var.aws_region
profile = var.aws_profile
default_tags {
tags = {
ClusterName = var.cluster_name
}
tags = merge(
{
"ClusterName" = var.cluster_name
},
var.custom_tags
)
}
}

Expand Down Expand Up @@ -104,7 +107,7 @@ resource "aws_iam_role" "metrics_role" {
}

resource "aws_iam_instance_profile" "metrics_profile" {
name = "metrics_profile"
name = "${var.cluster_name}-metrics_profile"
role = aws_iam_role.metrics_role.name
}

Expand Down
4 changes: 4 additions & 0 deletions deployment/terraform/assets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,9 @@ variable "aws_region" {
variable "aws_ami" {
}

variable "custom_tags" {
type = map(string)
}

variable "aws_az" {
}
1 change: 1 addition & 0 deletions deployment/terraform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (t *Terraform) getParams() []string {
"-var", fmt.Sprintf("redis_node_type=%s", t.config.RedisSettings.NodeType),
"-var", fmt.Sprintf("redis_param_group_name=%s", t.config.RedisSettings.ParameterGroupName),
"-var", fmt.Sprintf("redis_engine_version=%s", t.config.RedisSettings.EngineVersion),
"-var", fmt.Sprintf("custom_tags=%s", t.config.CustomTags),
}
}

Expand Down
6 changes: 6 additions & 0 deletions docs/config/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,9 @@ Enable continuous profiling of all the agent instances.
*int*

Set the pprof block profile rate. This value applies to both agent and Mattermost server processes.

## CustomTags

*map[string]string*

Optional map of key-value pairs, used to tag all deployed resources in AWS. Check [AWS documentation on tags](https://docs.aws.amazon.com/whitepapers/latest/tagging-best-practices/what-are-tags.html) for more information and best practices.

0 comments on commit a957878

Please sign in to comment.