Skip to content

Commit

Permalink
Merge pull request #29315 from ryoshindo/feat/appmesh-virtualnode-log…
Browse files Browse the repository at this point in the history
…format

feat: [appmesh] add logformat field for App Mesh Virtual Node
  • Loading branch information
ewbankkit authored Mar 20, 2023
2 parents e8fbc08 + 407ff06 commit 5a4d626
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .changelog/29315.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_appmesh_virtual_node: Add `logging.access_log.file.format` configuration block
```

```release-note:enhancement
resource/aws_appmesh_virtual_gateway: Add `logging.access_log.file.format` configuration block
```
57 changes: 53 additions & 4 deletions internal/service/appmesh/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,30 @@ func expandVirtualNodeSpec(vSpec []interface{}) *appmesh.VirtualNodeSpec {

mFile := vFile[0].(map[string]interface{})

if vFormat, ok := mFile["format"].([]interface{}); ok && len(vFormat) > 0 && vFormat[0] != nil {
format := &appmesh.LoggingFormat{}

mFormat := vFormat[0].(map[string]interface{})

if vJsonFormatRefs, ok := mFormat["json"].([]interface{}); ok && len(vJsonFormatRefs) > 0 {
jsonFormatRefs := []*appmesh.JsonFormatRef{}
for _, vJsonFormatRef := range vJsonFormatRefs {
mJsonFormatRef := &appmesh.JsonFormatRef{
Key: aws.String(vJsonFormatRef.(map[string]interface{})["key"].(string)),
Value: aws.String(vJsonFormatRef.(map[string]interface{})["value"].(string)),
}
jsonFormatRefs = append(jsonFormatRefs, mJsonFormatRef)
}
format.Json = jsonFormatRefs
}

if vText, ok := mFormat["text"].(string); ok && vText != "" {
format.Text = aws.String(vText)
}

file.Format = format
}

if vPath, ok := mFile["path"].(string); ok && vPath != "" {
file.Path = aws.String(vPath)
}
Expand Down Expand Up @@ -1720,11 +1744,36 @@ func flattenVirtualNodeSpec(spec *appmesh.VirtualNodeSpec) []interface{} {
mAccessLog := map[string]interface{}{}

if file := accessLog.File; file != nil {
mAccessLog["file"] = []interface{}{
map[string]interface{}{
"path": aws.StringValue(file.Path),
},
mFile := map[string]interface{}{}

if format := file.Format; format != nil {
mFormat := map[string]interface{}{}

if jsons := format.Json; jsons != nil {
vJsons := []interface{}{}

for _, j := range format.Json {
mJson := map[string]interface{}{
"key": aws.StringValue(j.Key),
"value": aws.StringValue(j.Value),
}

vJsons = append(vJsons, mJson)
}

mFormat["json"] = vJsons
}

if text := format.Text; text != nil {
mFormat["text"] = aws.StringValue(text)
}

mFile["format"] = []interface{}{mFormat}
}

mFile["path"] = aws.StringValue(file.Path)

mAccessLog["file"] = []interface{}{mFile}
}

mLogging["access_log"] = []interface{}{mAccessLog}
Expand Down
90 changes: 86 additions & 4 deletions internal/service/appmesh/virtual_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,39 @@ func ResourceVirtualGateway() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"format": {
Type: schema.TypeList,
Optional: true,
MinItems: 0,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"json": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
"value": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
},
},
},
"text": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
},
},
},
"path": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -1118,6 +1151,30 @@ func expandVirtualGatewaySpec(vSpec []interface{}) *appmesh.VirtualGatewaySpec {

mFile := vFile[0].(map[string]interface{})

if vFormat, ok := mFile["format"].([]interface{}); ok && len(vFormat) > 0 && vFormat[0] != nil {
format := &appmesh.LoggingFormat{}

mFormat := vFormat[0].(map[string]interface{})

if vJsonFormatRefs, ok := mFormat["json"].([]interface{}); ok && len(vJsonFormatRefs) > 0 {
jsonFormatRefs := []*appmesh.JsonFormatRef{}
for _, vJsonFormatRef := range vJsonFormatRefs {
mJsonFormatRef := &appmesh.JsonFormatRef{
Key: aws.String(vJsonFormatRef.(map[string]interface{})["key"].(string)),
Value: aws.String(vJsonFormatRef.(map[string]interface{})["value"].(string)),
}
jsonFormatRefs = append(jsonFormatRefs, mJsonFormatRef)
}
format.Json = jsonFormatRefs
}

if vText, ok := mFormat["text"].(string); ok && vText != "" {
format.Text = aws.String(vText)
}

file.Format = format
}

if vPath, ok := mFile["path"].(string); ok && vPath != "" {
file.Path = aws.String(vPath)
}
Expand Down Expand Up @@ -1430,11 +1487,36 @@ func flattenVirtualGatewaySpec(spec *appmesh.VirtualGatewaySpec) []interface{} {
mAccessLog := map[string]interface{}{}

if file := accessLog.File; file != nil {
mAccessLog["file"] = []interface{}{
map[string]interface{}{
"path": aws.StringValue(file.Path),
},
mFile := map[string]interface{}{}

if format := file.Format; format != nil {
mFormat := map[string]interface{}{}

if jsons := format.Json; jsons != nil {
vJsons := []interface{}{}

for _, j := range format.Json {
mJson := map[string]interface{}{
"key": aws.StringValue(j.Key),
"value": aws.StringValue(j.Value),
}

vJsons = append(vJsons, mJson)
}

mFormat["json"] = vJsons
}

if text := format.Text; text != nil {
mFormat["text"] = aws.StringValue(text)
}

mFile["format"] = []interface{}{mFormat}
}

mFile["path"] = aws.StringValue(file.Path)

mAccessLog["file"] = []interface{}{mFile}
}

mLogging["access_log"] = []interface{}{mAccessLog}
Expand Down
76 changes: 72 additions & 4 deletions internal/service/appmesh/virtual_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,20 @@ func testAccVirtualGateway_Logging(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.path", "/dev/stdout"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
acctest.CheckResourceAttrAccountID(resourceName, "resource_owner"),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualGateway/%s", meshName, vgName)),
),
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("%s/%s", meshName, vgName),
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccVirtualGatewayConfig_logging(meshName, vgName, "/tmp/access.log"),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -821,6 +828,7 @@ func testAccVirtualGateway_Logging(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.path", "/tmp/access.log"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
Expand All @@ -829,10 +837,33 @@ func testAccVirtualGateway_Logging(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("%s/%s", meshName, vgName),
ImportState: true,
ImportStateVerify: true,
Config: testAccVirtualGatewayConfig_loggingWithFormat(meshName, vgName, "/tmp/access.log"),
Check: resource.ComposeTestCheckFunc(
testAccCheckVirtualGatewayExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
acctest.CheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "name", vgName),
resource.TestCheckResourceAttr(resourceName, "spec.0.backend_defaults.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.listener.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.health_check.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.0.port", "8080"),
resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.0.protocol", "http"),
resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.tls.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.0.json.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.0.json.0.key", "k1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.0.json.0.value", "v1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.format.0.text", ""),
resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.0.path", "/tmp/access.log"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
acctest.CheckResourceAttrAccountID(resourceName, "resource_owner"),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualGateway/%s", meshName, vgName)),
),
},
},
})
Expand Down Expand Up @@ -1561,6 +1592,43 @@ resource "aws_appmesh_virtual_gateway" "test" {
`, meshName, vgName, path)
}

func testAccVirtualGatewayConfig_loggingWithFormat(meshName, vgName, path string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "test" {
name = %[1]q
}
resource "aws_appmesh_virtual_gateway" "test" {
name = %[2]q
mesh_name = aws_appmesh_mesh.test.id
spec {
listener {
port_mapping {
port = 8080
protocol = "http"
}
}
logging {
access_log {
file {
path = %[3]q
format {
json {
key = "k1"
value = "v1"
}
}
}
}
}
}
}
`, meshName, vgName, path)
}

func testAccVirtualGatewayConfig_tags1(meshName, vgName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "test" {
Expand Down
33 changes: 33 additions & 0 deletions internal/service/appmesh/virtual_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,39 @@ func ResourceVirtualNode() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"format": {
Type: schema.TypeList,
Optional: true,
MinItems: 0,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"json": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
"value": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
},
},
},
"text": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
},
},
},
"path": {
Type: schema.TypeString,
Required: true,
Expand Down
Loading

0 comments on commit 5a4d626

Please sign in to comment.