Skip to content

Commit

Permalink
feat(ocean/aws): new field: logging (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
guyalt3 authored Dec 9, 2021
1 parent 8a73fc4 commit b49397e
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Unreleased

ENHANCEMENTS:
* resource/spotinst_ocean_aws: added support for `logging`

## 1.63.0 (November 29, 2021)

ENHANCEMENTS:
* resource/spotinst_ocean_gke_launch_spec: added support for `scheduling`
* resource/spotinst_ocean_aws_launch_spec: added support for `scheduling`
* resource/spotinst_ocean_ecs_launch_spec: added support for `scheduling`
Expand Down
12 changes: 12 additions & 0 deletions docs/resources/ocean_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ resource "spotinst_ocean_aws" "example" {
http_tokens = "required"
http_put_response_hop_limit = 10
}
logging {
export {
s3 {
id = "di-abcd123"
}
}
}
}
```
```
Expand Down Expand Up @@ -133,6 +141,10 @@ The following arguments are supported:
* `instance_metadata_options` - (Optional) Ocean instance metadata options object for IMDSv2.
* `http_tokens` - (Required) Determines if a signed token is required or not. Valid values: `optional` or `required`.
* `http_put_response_hop_limit` - (Optional) An integer from 1 through 64. The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further the instance metadata requests can travel.
* `logging` - (Optional) Logging configuration.
* `export` - (Optional) Logging Export configuration.
* `s3` - (Optional) Exports your cluster's logs to the S3 bucket and subdir configured on the S3 data integration given.
* `id` - (Required) The identifier of The S3 data integration to export the logs to.

<a id="auto-scaler"></a>
## Auto Scaler
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ require (
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/terraform-plugin-docs v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/spotinst/spotinst-sdk-go v1.105.0
github.com/spotinst/spotinst-sdk-go v1.107.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
)
16 changes: 12 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
Expand All @@ -71,6 +72,7 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkE
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
Expand Down Expand Up @@ -104,7 +106,9 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
Expand All @@ -115,6 +119,7 @@ github.com/go-git/go-billy/v5 v5.3.1 h1:CPiOUAzKtMRvolEKw+bG1PLRpT7D3LIs3/3ey4Ai
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git-fixtures/v4 v4.2.1 h1:n9gGL1Ct/yIw+nfsfr8s4+sbhT+Ncu2SubfXjIWgci8=
github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0=
github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4X+lNVprw=
Expand Down Expand Up @@ -296,6 +301,7 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
Expand Down Expand Up @@ -340,6 +346,7 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -360,8 +367,8 @@ github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spotinst/spotinst-sdk-go v1.105.0 h1:U3Zd4Jhv98HWx3oVTY3dHEfyNWF73sk3YQszY+6/JBk=
github.com/spotinst/spotinst-sdk-go v1.105.0/go.mod h1:vh6NZX3sECLqWQyW0MSTth5BdL7x7jR7UsGIxr9J3Cw=
github.com/spotinst/spotinst-sdk-go v1.107.0 h1:7bUHoQ2OqczJ6TpB2gOG5lWoTVCjq2LWQKIL6w2XHPM=
github.com/spotinst/spotinst-sdk-go v1.107.0/go.mod h1:Z5OIb6PgAOUr7Eb9X72wkY7/OCaFntrNzF/Hl9o6cQU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down Expand Up @@ -541,6 +548,7 @@ golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -695,8 +703,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.64.0 h1:Mj2zXEXcNb5joEiSA0zc3HZpTst/iyjNiR4CN8tDzOg=
gopkg.in/ini.v1 v1.64.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
1 change: 1 addition & 0 deletions spotinst/commons/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
OceanAWSStrategy ResourceAffinity = "Ocean_AWS_Strategy"
OceanAWSScheduling ResourceAffinity = "Ocean_AWS_Scheduling"
OceanAWSLaunchConfiguration ResourceAffinity = "Ocean_AWS_Launch_Configuration"
OceanAwsLogging ResourceAffinity = "Ocean_AWS_Logging"

OceanAWSLaunchSpec ResourceAffinity = "Ocean_AWS_Launch_Spec"

Expand Down
12 changes: 12 additions & 0 deletions spotinst/ocean_aws_logging/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ocean_aws_logging

import (
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons"
)

const (
Logging commons.FieldName = "logging"
Export commons.FieldName = "export"
S3 commons.FieldName = "s3"
Id commons.FieldName = "id"
)
208 changes: 208 additions & 0 deletions spotinst/ocean_aws_logging/fields_spotinst_ocean_aws_logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
package ocean_aws_logging

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/spotinst/spotinst-sdk-go/service/ocean/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons"
)

func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {

fieldsMap[Logging] = commons.NewGenericField(
commons.OceanAwsLogging,
Logging,
&schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(Export): {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(S3): {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(Id): {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
},
},
},
},
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.AWSClusterWrapper)
cluster := clusterWrapper.GetCluster()
var result []interface{} = nil
if cluster != nil && cluster.Logging != nil {
result = flattenLogging(cluster.Logging)
}
if len(result) > 0 {
if err := resourceData.Set(string(Logging), result); err != nil {
return fmt.Errorf(string(commons.FailureFieldReadPattern), string(Logging), err)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.AWSClusterWrapper)
cluster := clusterWrapper.GetCluster()
if v, ok := resourceData.GetOk(string(Logging)); ok {
if logging, err := expandOceanAWSLogging(v); err != nil {
return err
} else {
cluster.SetLogging(logging)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
clusterWrapper := resourceObject.(*commons.AWSClusterWrapper)
cluster := clusterWrapper.GetCluster()
var value *aws.Logging = nil

if v, ok := resourceData.GetOk(string(Logging)); ok {
if logging, err := expandOceanAWSLogging(v); err != nil {
return err
} else {
value = logging
}
}
cluster.SetLogging(value)
return nil
},
nil,
)
}

func flattenLogging(logging *aws.Logging) []interface{} {
var out []interface{}

if logging != nil {
result := make(map[string]interface{})

if logging.Export != nil {
result[string(Export)] = flattenExport(logging.Export)
}

if len(result) > 0 {
out = append(out, result)
}
}

return out
}

func flattenExport(export *aws.Export) []interface{} {
var out []interface{}

if export != nil {
result := make(map[string]interface{})

if export.S3 != nil {
result[string(S3)] = flattenS3(export.S3)
}

if len(result) > 0 {
out = append(out, result)
}
}

return out
}

func flattenS3(s3 *aws.S3) []interface{} {
var out []interface{}

if s3 != nil {
result := make(map[string]interface{})

if s3.ID != nil {
result[string(Id)] = s3.ID
}

if len(result) > 0 {
out = append(out, result)
}
}

return out
}

func expandOceanAWSLogging(data interface{}) (*aws.Logging, error) {
logging := &aws.Logging{}
list := data.([]interface{})

if list == nil || list[0] == nil {
return logging, nil
}
m := list[0].(map[string]interface{})

if v, ok := m[string(Export)]; ok {
export, err := expandOceanAWSExport(v)
if err != nil {
return nil, err
}
if export != nil {
logging.SetExport(export)
} else {
logging.Export = nil
}
}

return logging, nil
}

func expandOceanAWSExport(data interface{}) (*aws.Export, error) {
export := &aws.Export{}
list := data.([]interface{})

if list == nil || list[0] == nil {
return export, nil
}
m := list[0].(map[string]interface{})

if v, ok := m[string(S3)]; ok {
s3, err := expandOceanAWSS3(v)
if err != nil {
return nil, err
}
if s3 != nil {
export.SetS3(s3)
} else {
export.S3 = nil
}
}

return export, nil
}

func expandOceanAWSS3(data interface{}) (*aws.S3, error) {
s3 := &aws.S3{}
list := data.([]interface{})

if list == nil || list[0] == nil {
return s3, nil
}
m := list[0].(map[string]interface{})

if v, ok := m[string(Id)].(string); ok && v != "" {
s3.SetId(spotinst.String(v))
}

return s3, nil
}
2 changes: 2 additions & 0 deletions spotinst/resource_spotinst_ocean_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spotinst/terraform-provider-spotinst/spotinst/ocean_aws_auto_scaling"
"github.com/spotinst/terraform-provider-spotinst/spotinst/ocean_aws_instance_types"
"github.com/spotinst/terraform-provider-spotinst/spotinst/ocean_aws_launch_configuration"
"github.com/spotinst/terraform-provider-spotinst/spotinst/ocean_aws_logging"
"github.com/spotinst/terraform-provider-spotinst/spotinst/ocean_aws_scheduling"
"github.com/spotinst/terraform-provider-spotinst/spotinst/ocean_aws_strategy"
)
Expand Down Expand Up @@ -46,6 +47,7 @@ func setupClusterAWSResource() {
ocean_aws_launch_configuration.Setup(fieldsMap)
ocean_aws_strategy.Setup(fieldsMap)
ocean_aws_scheduling.Setup(fieldsMap)
ocean_aws_logging.Setup(fieldsMap)

commons.OceanAWSResource = commons.NewOceanAWSResource(fieldsMap)
}
Expand Down
Loading

0 comments on commit b49397e

Please sign in to comment.