diff --git a/go.mod b/go.mod index 6bbdd82fd0..eb5c30b11c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/Azure/go-autorest/autorest/azure/auth v0.5.1 github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect github.com/aws/aws-lambda-go v1.13.3 - github.com/aws/aws-sdk-go v1.27.1 + github.com/aws/aws-sdk-go v1.38.28 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/docker/cli v0.0.0-20200109221225-a4f60165b7a3 // indirect github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect @@ -38,7 +38,7 @@ require ( github.com/urfave/cli v1.22.2 github.com/zclconf/go-cty v1.2.1 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 - golang.org/x/net v0.0.0-20201021035429-f5854403a974 + golang.org/x/net v0.0.0-20201110031124-69a78807bb2b golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/tools v0.0.0-20201110201400-7099162a900a // indirect google.golang.org/api v0.15.0 diff --git a/go.sum b/go.sum index 06c34b174e..c7288882a6 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQ github.com/aws/aws-sdk-go v1.16.26/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.27.1 h1:MXnqY6SlWySaZAqNnXThOvjRFdiiOuKtC6i7baFdNdU= github.com/aws/aws-sdk-go v1.27.1/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go v1.38.28 h1:2ZzgEupSluR18ClxUnHwXKyuADheZpMblXRAsHqF0tI= +github.com/aws/aws-sdk-go v1.38.28/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= 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= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= @@ -275,6 +277,9 @@ github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt7 github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -501,6 +506,8 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= diff --git a/modules/aws/auth.go b/modules/aws/auth.go index 2a0a0f6c91..f2aa6f78c5 100644 --- a/modules/aws/auth.go +++ b/modules/aws/auth.go @@ -30,7 +30,14 @@ func NewAuthenticatedSession(region string) (*session.Session, error) { // NewAuthenticatedSessionFromDefaultCredentials gets an AWS Session, checking that the user has credentials properly configured in their environment. func NewAuthenticatedSessionFromDefaultCredentials(region string) (*session.Session, error) { - sess, err := session.NewSession(aws.NewConfig().WithRegion(region)) + awsConfig := aws.NewConfig().WithRegion(region) + + sessionOptions := session.Options{ + Config: *awsConfig, + SharedConfigState: session.SharedConfigEnable, + } + + sess, err := session.NewSessionWithOptions(sessionOptions) if err != nil { return nil, err } diff --git a/modules/k8s/version.go b/modules/k8s/version.go new file mode 100644 index 0000000000..622272d85b --- /dev/null +++ b/modules/k8s/version.go @@ -0,0 +1,30 @@ +package k8s + +import "github.com/gruntwork-io/terratest/modules/testing" + +// GetKubernetesClusterVersion returns the Kubernetes cluster version. +func GetKubernetesClusterVersionE(t testing.TestingT) (string, error) { + kubeConfigPath, err := GetKubeConfigPathE(t) + if err != nil { + return "", err + } + + options := NewKubectlOptions("", kubeConfigPath, "default") + + return GetKubernetesClusterVersionWithOptionsE(t, options) +} + +// GetKubernetesClusterVersion returns the Kubernetes cluster version given a configured KubectlOptions object. +func GetKubernetesClusterVersionWithOptionsE(t testing.TestingT, kubectlOptions *KubectlOptions) (string, error) { + clientset, err := GetKubernetesClientFromOptionsE(t, kubectlOptions) + if err != nil { + return "", err + } + + versionInfo, err := clientset.DiscoveryClient.ServerVersion() + if err != nil { + return "", err + } + + return versionInfo.String(), nil +} diff --git a/modules/k8s/version_test.go b/modules/k8s/version_test.go new file mode 100644 index 0000000000..f4d467b4b2 --- /dev/null +++ b/modules/k8s/version_test.go @@ -0,0 +1,61 @@ +// +build kubeall kubernetes + +// NOTE: we have build tags to differentiate kubernetes tests from non-kubernetes tests. This is done because minikube +// is heavy and can interfere with docker related tests in terratest. Specifically, many of the tests start to fail with +// `connection refused` errors from `minikube`. To avoid overloading the system, we run the kubernetes tests and helm +// tests separately from the others. This may not be necessary if you have a sufficiently powerful machine. We +// recommend at least 4 cores and 16GB of RAM if you want to run all the tests together. + +package k8s + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type KubectlVersion struct { + ServerVersion struct { + GitVersion string `json:"gitVersion"` + } `json:"serverVersion"` +} + +func TestGetKubernetesClusterVersionE(t *testing.T) { + t.Parallel() + + kubernetesClusterVersion, err := GetKubernetesClusterVersionE(t) + require.NoError(t, err) + + options := NewKubectlOptions("", "", "") + kubernetesClusterVersionFromKubectl, err := RunKubectlAndGetOutputE(t, options, "version", "-o", "json") + require.NoError(t, err) + + var kctlClusterVersion KubectlVersion + require.NoError( + t, + json.Unmarshal([]byte(kubernetesClusterVersionFromKubectl), &kctlClusterVersion), + ) + + assert.EqualValues(t, kubernetesClusterVersion, kctlClusterVersion.ServerVersion.GitVersion) +} + +func TestGetKubernetesClusterVersionWithOptionsE(t *testing.T) { + t.Parallel() + + options := NewKubectlOptions("", "", "") + kubernetesClusterVersion, err := GetKubernetesClusterVersionWithOptionsE(t, options) + require.NoError(t, err) + + kubernetesClusterVersionFromKubectl, err := RunKubectlAndGetOutputE(t, options, "version", "-o", "json") + require.NoError(t, err) + + var kctlClusterVersion KubectlVersion + require.NoError( + t, + json.Unmarshal([]byte(kubernetesClusterVersionFromKubectl), &kctlClusterVersion), + ) + + assert.EqualValues(t, kubernetesClusterVersion, kctlClusterVersion.ServerVersion.GitVersion) +} diff --git a/modules/terraform/options.go b/modules/terraform/options.go index 6182ea0020..b0fe85b9bd 100644 --- a/modules/terraform/options.go +++ b/modules/terraform/options.go @@ -1,11 +1,11 @@ package terraform import ( - "testing" "time" "github.com/gruntwork-io/terratest/modules/logger" "github.com/gruntwork-io/terratest/modules/ssh" + "github.com/gruntwork-io/terratest/modules/testing" "github.com/jinzhu/copier" "github.com/stretchr/testify/require" ) @@ -86,7 +86,7 @@ func (options *Options) Clone() (*Options, error) { // for retryable errors. The included retryable errors are typical errors that most terraform modules encounter during // testing, and are known to self resolve upon retrying. // This will fail the test if there are any errors in the cloning process. -func WithDefaultRetryableErrors(t *testing.T, originalOptions *Options) *Options { +func WithDefaultRetryableErrors(t testing.TestingT, originalOptions *Options) *Options { newOptions, err := originalOptions.Clone() require.NoError(t, err)