diff --git a/README.md b/README.md index 8f001e3..cccb42b 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,10 @@ The following `secrets` are valid on an AWS host catalog resource: The following attributes are valid on an AWS host Set resource: -- `filters` (object): An object of filters to filter off of. For a list of - filter options, check out [describe-instances in the AWS CLI +- `filters` (array of strings): An array of string filters in the format + `key=val1,val2`. The key corresponds to a filter option, and the value(s) are + a comma-separated list. For a list of filter options, check out + [describe-instances in the AWS CLI reference](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html). #### Supplying Filters on the Boundary CLI diff --git a/go.mod b/go.mod index 3ec1584..d5008be 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,13 @@ module github.com/hashicorp/boundary-plugin-host-aws go 1.16 require ( - github.com/aws/aws-sdk-go v1.40.55 + github.com/aws/aws-sdk-go v1.41.16 github.com/fatih/color v1.13.0 // indirect github.com/hashicorp/boundary/sdk v0.0.12-0.20211028194642-6eba8a478703 github.com/hashicorp/go-secure-stdlib/awsutil v0.1.6 - github.com/hashicorp/terraform-json v0.12.0 + github.com/hashicorp/terraform-json v0.13.0 github.com/mattn/go-colorable v0.1.11 // indirect + github.com/mitchellh/mapstructure v1.4.2 github.com/stretchr/testify v1.7.0 golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef // indirect diff --git a/go.sum b/go.sum index 1758368..2bc459f 100644 --- a/go.sum +++ b/go.sum @@ -54,7 +54,6 @@ github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSW github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc= github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= github.com/Azure/go-autorest/autorest/to v0.3.0 h1:zebkZaadz7+wIQYgC7GXaz3Wb28yKYfVkkBKwc38VF8= github.com/Azure/go-autorest/autorest/to v0.3.0/go.mod h1:MgwOyqaIuKdG4TL/2ywSsIWKAfJfgHDo8ObuUk3t5sA= @@ -84,7 +83,7 @@ github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190620160927-9418d7b0cd0f h1:oRD github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190620160927-9418d7b0cd0f/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/armon/go-metrics v0.3.0/go.mod h1:zXjbSimjXTd7vOpY8B0/2LpvNvDoXBuplAD+gJD3GYs= github.com/armon/go-metrics v0.3.3/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= @@ -92,8 +91,8 @@ 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/aws/aws-sdk-go v1.25.37/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.30.27/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= -github.com/aws/aws-sdk-go v1.40.55 h1:l5xNBmafEAfdJIIe32QbTLG3j/JscH8fzZqYyMlntuI= -github.com/aws/aws-sdk-go v1.40.55/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= +github.com/aws/aws-sdk-go v1.41.16 h1:rNbPreEO4K2b8LwhHOe5+iNRH3Ih35L+H9U5tLdcevo= +github.com/aws/aws-sdk-go v1.41.16/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -150,7 +149,6 @@ github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/frankban/quicktest v1.10.0 h1:Gfh+GAJZOAoKZsIZeZbdn2JF10kN1XHNvjsvQK8gVkE= github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -187,7 +185,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -238,7 +235,6 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= @@ -306,13 +302,15 @@ github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2I github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw= +github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/terraform-json v0.12.0 h1:8czPgEEWWPROStjkWPUnTQDXmpmZPlkQAwYYLETaTvw= -github.com/hashicorp/terraform-json v0.12.0/go.mod h1:pmbq9o4EuL43db5+0ogX10Yofv1nozM+wskr/bGFJpI= +github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY= +github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk= github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE= github.com/hashicorp/vault/api v1.1.1 h1:907ld+Z9cALyvbZK2qUX9cLwvSaEQsMVQB3x2KE8+AI= github.com/hashicorp/vault/api v1.1.1/go.mod h1:29UXcn/1cLOPHQNMWA7bCz2By4PSd0VKPAydKXS5yN0= @@ -343,7 +341,6 @@ github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -360,7 +357,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 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/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -389,8 +385,9 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.4.2 h1:6h7AQ0yhTcIsmFmnAwQls75jp2Gzs4iB8W7pjMO+rqo= +github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -462,10 +459,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8= github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= @@ -474,7 +469,6 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 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/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -486,7 +480,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/tencentcloud/tencentcloud-sdk-go v1.0.162/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/yandex-cloud/go-genproto v0.0.0-20200722140432-762fe965ce77/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE= github.com/yandex-cloud/go-sdk v0.0.0-20200722140627-2194e5077f13/go.mod h1:LEdAMqa1v/7KYe4b13ALLkonuDxLph57ibUb50ctvJk= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -494,8 +489,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8= -github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.9.1 h1:viqrgQwFl5UpSxc046qblj78wZXVDFnSOufaOTER+cc= +github.com/zclconf/go-cty v1.9.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -553,10 +548,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/plugin/plugin.go b/plugin/plugin.go index 2f276e6..c17123c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "time" "github.com/aws/aws-sdk-go/aws" @@ -11,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/ec2" pb "github.com/hashicorp/boundary/sdk/pbs/plugin" + "github.com/mitchellh/mapstructure" "google.golang.org/protobuf/types/known/structpb" ) @@ -33,6 +35,12 @@ var ( _ pb.HostPluginServiceServer = (*AwsPlugin)(nil) ) +// SetAttributes is a Go-native representation of the Attributes map that can be +// used for decoding the incoming map via mapstructure. +type SetAttributes struct { + Filters []string +} + func (p *AwsPlugin) OnCreateCatalog(ctx context.Context, req *pb.OnCreateCatalogRequest) (*pb.OnCreateCatalogResponse, error) { catalog := req.GetCatalog() if catalog == nil { @@ -242,10 +250,13 @@ func (p *AwsPlugin) OnCreateSet(ctx context.Context, req *pb.OnCreateSetRequest) return nil, errors.New("set is nil") } - setAttrs := set.GetAttributes() - if setAttrs == nil { + if set.GetAttributes() == nil { return nil, errors.New("set missing attributes") } + setAttrs, err := getSetAttributes(set.GetAttributes()) + if err != nil { + return nil, fmt.Errorf("error parsing set attributes: %w", err) + } ec2Client, err := state.EC2Client(region) if err != nil { @@ -299,9 +310,12 @@ func (p *AwsPlugin) OnUpdateSet(ctx context.Context, req *pb.OnUpdateSetRequest) return nil, errors.New("new set is nil") } - setAttrs := set.GetAttributes() - if setAttrs == nil { - return nil, errors.New("new set missing attributes") + if set.GetAttributes() == nil { + return nil, errors.New("set missing attributes") + } + setAttrs, err := getSetAttributes(set.GetAttributes()) + if err != nil { + return nil, fmt.Errorf("error parsing set attributes: %w", err) } ec2Client, err := state.EC2Client(region) @@ -375,10 +389,13 @@ func (p *AwsPlugin) ListHosts(ctx context.Context, req *pb.ListHostsRequest) (*p return nil, errors.New("set missing id") } - setAttrs := set.GetAttributes() - if setAttrs == nil { + if set.GetAttributes() == nil { return nil, errors.New("set missing attributes") } + setAttrs, err := getSetAttributes(set.GetAttributes()) + if err != nil { + return nil, fmt.Errorf("error parsing set attributes: %w", err) + } input, err := buildDescribeInstancesInput(setAttrs, false) if err != nil { @@ -514,19 +531,14 @@ func getTimeValue(in *structpb.Struct, k string) (time.Time, error) { return t, nil } -func getMapValue(in *structpb.Struct, k string) (map[string]interface{}, error) { - mv := in.AsMap() - v, ok := mv[k] - if !ok { - return make(map[string]interface{}), nil +func getSetAttributes(in *structpb.Struct) (*SetAttributes, error) { + var setAttrs SetAttributes + + if err := mapstructure.Decode(in.AsMap(), &setAttrs); err != nil { + return nil, fmt.Errorf("error decoding set attributes: %w", err) } - m, ok := v.(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("unexpected type for value %q: want map, got %T", k, v) - } - - return m, nil + return &setAttrs, nil } func getValidateRegionValue(in *structpb.Struct) (string, error) { @@ -543,36 +555,33 @@ func getValidateRegionValue(in *structpb.Struct) (string, error) { return region, nil } -func buildFilters(in *structpb.Struct) ([]*ec2.Filter, error) { +func buildFilters(attrs *SetAttributes) ([]*ec2.Filter, error) { var filters []*ec2.Filter - m, err := getMapValue(in, constDescribeInstancesFilters) - if err != nil { - return nil, err - } - var foundStateFilter bool - for k, v := range m { - if k == "instance-state-code" || k == "instance-state-name" { + for _, filterAttr := range attrs.Filters { + // Each filter arrives in "k=v1,v2" format. First, split on equal sign. + splitFilter := strings.Split(filterAttr, "=") + switch { + case len(splitFilter) != 2: + return nil, fmt.Errorf("expected filter %q to contain a single equal sign", filterAttr) + case len(splitFilter[0]) == 0: + return nil, fmt.Errorf("filter %q contains an empty filter key", filterAttr) + case len(splitFilter[1]) == 0: + return nil, fmt.Errorf("filter %q contains an empty value", filterAttr) + } + + filterKey, filterValue := splitFilter[0], splitFilter[1] + if filterKey == "instance-state-code" || filterKey == "instance-state-name" { foundStateFilter = true } - w, ok := v.([]interface{}) - if !ok { - return nil, fmt.Errorf("unexpected type for filter values in %q: want array, got %T", k, v) - } - var filterValues []*string - for _, e := range w { - f, ok := e.(string) - if !ok { - return nil, fmt.Errorf("unexpected type for filter element value %v: want string, got %T", e, e) - } - - filterValues = append(filterValues, aws.String(f)) + for _, val := range strings.Split(filterValue, ",") { + filterValues = append(filterValues, aws.String(val)) } filters = append(filters, &ec2.Filter{ - Name: aws.String(k), + Name: aws.String(filterKey), Values: filterValues, }) } @@ -591,7 +600,7 @@ func buildFilters(in *structpb.Struct) ([]*ec2.Filter, error) { return filters, nil } -func buildDescribeInstancesInput(attrs *structpb.Struct, dryRun bool) (*ec2.DescribeInstancesInput, error) { +func buildDescribeInstancesInput(attrs *SetAttributes, dryRun bool) (*ec2.DescribeInstancesInput, error) { filters, err := buildFilters(attrs) if err != nil { return nil, fmt.Errorf("error building filters: %w", err) diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index 3f9fd9d..73ac7e9 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -1386,38 +1386,42 @@ func TestGetTimeValue(t *testing.T) { } } -func TestGetMapValue(t *testing.T) { +func TestGetSetAttributes(t *testing.T) { cases := []struct { - name string - in *structpb.Struct - key string - expected map[string]interface{} - expectedErr string + name string + in *structpb.Struct + expected *SetAttributes + expectedErrContains string }{ { name: "missing", in: mustStruct(map[string]interface{}{}), - key: "foo", - expected: make(map[string]interface{}), + expected: &SetAttributes{}, }, { - name: "non-map value", + name: "non-string-slice value", in: mustStruct(map[string]interface{}{ - "foo": "bar", + constDescribeInstancesFilters: "bar", }), - key: "foo", - expectedErr: "unexpected type for value \"foo\": want map, got string", + expectedErrContains: "source data must be an array or slice, got string", + }, + { + name: "bad filter element value", + in: mustStruct(map[string]interface{}{ + constDescribeInstancesFilters: []interface{}{1}, + }), + expectedErrContains: "expected type 'string', got unconvertible type 'float64'", }, { name: "good", in: mustStruct(map[string]interface{}{ - "foo": map[string]interface{}{ - "one": "two", + constDescribeInstancesFilters: []interface{}{ + "foo=bar", + "zip=zap", }, }), - key: "foo", - expected: map[string]interface{}{ - "one": "two", + expected: &SetAttributes{ + Filters: []string{"foo=bar", "zip=zap"}, }, }, } @@ -1426,9 +1430,9 @@ func TestGetMapValue(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { require := require.New(t) - actual, err := getMapValue(tc.in, tc.key) - if tc.expectedErr != "" { - require.EqualError(err, tc.expectedErr) + actual, err := getSetAttributes(tc.in) + if tc.expectedErrContains != "" { + require.Contains(err.Error(), tc.expectedErrContains) return } @@ -1486,41 +1490,17 @@ func TestGetValidateRegionValue(t *testing.T) { func TestBuildFilters(t *testing.T) { cases := []struct { - name string - in *structpb.Struct - expected []*ec2.Filter - expectedErr string + name string + in *structpb.Struct + expected []*ec2.Filter + expectedErrContains string }{ - { - name: "map value error", - in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: "foo", - }), - expectedErr: fmt.Sprintf("unexpected type for value %q: want map, got string", constDescribeInstancesFilters), - }, - { - name: "bad filter values", - in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{ - "foo": "bar", - }, - }), - expectedErr: "unexpected type for filter values in \"foo\": want array, got string", - }, - { - name: "bad filter element value", - in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{ - "foo": []interface{}{1}, - }, - }), - expectedErr: "unexpected type for filter element value 1: want string, got float64", - }, + { name: "good without instance-state-name", in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{ - "foo": []interface{}{"bar"}, + constDescribeInstancesFilters: []interface{}{ + "foo=bar", }, }), expected: []*ec2.Filter{ @@ -1537,9 +1517,9 @@ func TestBuildFilters(t *testing.T) { { name: "good with instance-state-name", in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{ - "foo": []interface{}{"bar"}, - "instance-state-name": []interface{}{"static"}, + constDescribeInstancesFilters: []interface{}{ + "foo=bar", + "instance-state-name=static", }, }), expected: []*ec2.Filter{ @@ -1553,10 +1533,28 @@ func TestBuildFilters(t *testing.T) { }, }, }, + { + name: "good with multiple values", + in: mustStruct(map[string]interface{}{ + constDescribeInstancesFilters: []interface{}{ + "foo=bar,baz", + }, + }), + expected: []*ec2.Filter{ + &ec2.Filter{ + Name: aws.String("foo"), + Values: aws.StringSlice([]string{"bar", "baz"}), + }, + &ec2.Filter{ + Name: aws.String("instance-state-name"), + Values: aws.StringSlice([]string{ec2.InstanceStateNameRunning}), + }, + }, + }, { name: "empty filter set", in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{}, + constDescribeInstancesFilters: []interface{}{}, }), expected: []*ec2.Filter{ &ec2.Filter{ @@ -1571,9 +1569,11 @@ func TestBuildFilters(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { require := require.New(t) - actual, err := buildFilters(tc.in) - if tc.expectedErr != "" { - require.EqualError(err, tc.expectedErr) + attrs, err := getSetAttributes(tc.in) + require.NoError(err) + actual, err := buildFilters(attrs) + if tc.expectedErrContains != "" { + require.Contains(err.Error(), tc.expectedErrContains) return } @@ -1592,18 +1592,11 @@ func TestBuildDescribeInstancesInput(t *testing.T) { expected *ec2.DescribeInstancesInput expectedErr string }{ - { - name: "buildFilters error", - in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: "foo", - }), - expectedErr: fmt.Sprintf("error building filters: unexpected type for value %q: want map, got string", constDescribeInstancesFilters), - }, { name: "good, dry run", in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{ - "foo": []interface{}{"bar"}, + constDescribeInstancesFilters: []interface{}{ + "foo=bar", }, }), dryRun: true, @@ -1624,8 +1617,8 @@ func TestBuildDescribeInstancesInput(t *testing.T) { { name: "good, real run", in: mustStruct(map[string]interface{}{ - constDescribeInstancesFilters: map[string]interface{}{ - "foo": []interface{}{"bar"}, + constDescribeInstancesFilters: []interface{}{ + "foo=bar", }, }), dryRun: false, @@ -1649,7 +1642,9 @@ func TestBuildDescribeInstancesInput(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { require := require.New(t) - actual, err := buildDescribeInstancesInput(tc.in, tc.dryRun) + attrs, err := getSetAttributes(tc.in) + require.NoError(err) + actual, err := buildDescribeInstancesInput(attrs, tc.dryRun) if tc.expectedErr != "" { require.EqualError(err, tc.expectedErr) return