2022-09-26 09:52:31 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
2023-05-22 07:31:20 -04:00
|
|
|
"bytes"
|
2022-09-26 09:52:31 -04:00
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"io/fs"
|
2022-12-07 05:48:54 -05:00
|
|
|
"path"
|
2022-11-14 12:18:58 -05:00
|
|
|
"path/filepath"
|
2022-12-07 05:48:54 -05:00
|
|
|
"strings"
|
2022-09-26 09:52:31 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
2022-11-14 12:18:58 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
2022-09-26 09:52:31 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
2023-06-28 08:42:34 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/role"
|
2023-11-22 08:52:56 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/state"
|
2022-09-26 09:52:31 -04:00
|
|
|
"github.com/hashicorp/terraform-exec/tfexec"
|
|
|
|
tfjson "github.com/hashicorp/terraform-json"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-19 07:02:01 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-09-26 09:52:31 -04:00
|
|
|
)
|
|
|
|
|
2023-06-19 07:02:01 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m)
|
|
|
|
}
|
|
|
|
|
2022-11-15 08:00:44 -05:00
|
|
|
func TestPrepareCluster(t *testing.T) {
|
|
|
|
qemuVars := &QEMUVariables{
|
2023-06-28 08:42:34 -04:00
|
|
|
Name: "name",
|
|
|
|
NodeGroups: map[string]QEMUNodeGroup{
|
|
|
|
"control-plane": {
|
|
|
|
Role: role.ControlPlane.TFString(),
|
|
|
|
DiskSize: 30,
|
|
|
|
CPUCount: 1,
|
|
|
|
MemorySize: 1024,
|
|
|
|
},
|
2022-11-15 08:00:44 -05:00
|
|
|
},
|
2023-06-28 08:42:34 -04:00
|
|
|
Machine: "q35",
|
2022-11-15 08:00:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
2022-12-07 05:48:54 -05:00
|
|
|
pathBase string
|
2022-11-15 08:00:44 -05:00
|
|
|
provider cloudprovider.Provider
|
|
|
|
vars Variables
|
|
|
|
fs afero.Fs
|
|
|
|
partiallyExtracted bool
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"qemu": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-11-15 08:00:44 -05:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
"no vars": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-11-15 08:00:44 -05:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"continue on partially extracted": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-11-15 08:00:44 -05:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
partiallyExtracted: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
"prepare workspace fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-11-15 08:00:44 -05:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
|
|
|
fs: afero.NewReadOnlyFs(afero.NewMemMapFs()),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
|
|
|
tf: &stubTerraform{},
|
|
|
|
file: file.NewHandler(tc.fs),
|
2023-08-04 07:53:51 -04:00
|
|
|
workingDir: "unittest",
|
2022-11-15 08:00:44 -05:00
|
|
|
}
|
|
|
|
|
2022-12-07 05:48:54 -05:00
|
|
|
path := path.Join(tc.pathBase, strings.ToLower(tc.provider.String()))
|
|
|
|
err := c.PrepareWorkspace(path, tc.vars)
|
2022-11-15 08:00:44 -05:00
|
|
|
|
|
|
|
// Test case: Check if we can continue to create on an incomplete workspace.
|
|
|
|
if tc.partiallyExtracted {
|
|
|
|
require.NoError(c.file.Remove(filepath.Join(c.workingDir, "main.tf")))
|
2022-12-07 05:48:54 -05:00
|
|
|
err = c.PrepareWorkspace(path, tc.vars)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrepareIAM(t *testing.T) {
|
|
|
|
gcpVars := &GCPIAMVariables{
|
|
|
|
Project: "const-1234",
|
|
|
|
Region: "europe-west1",
|
|
|
|
Zone: "europe-west1-a",
|
|
|
|
ServiceAccountID: "const-test-case",
|
|
|
|
}
|
|
|
|
azureVars := &AzureIAMVariables{
|
2023-05-26 05:45:03 -04:00
|
|
|
Region: "westus",
|
|
|
|
ResourceGroup: "constell-test-rg",
|
2022-12-07 05:48:54 -05:00
|
|
|
}
|
|
|
|
awsVars := &AWSIAMVariables{
|
|
|
|
Region: "eu-east-2a",
|
|
|
|
Prefix: "test",
|
|
|
|
}
|
|
|
|
testCases := map[string]struct {
|
|
|
|
pathBase string
|
|
|
|
provider cloudprovider.Provider
|
|
|
|
vars Variables
|
|
|
|
fs afero.Fs
|
|
|
|
partiallyExtracted bool
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"no vars": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"invalid path": {
|
|
|
|
pathBase: path.Join("abc", "123"),
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"gcp": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
"continue on partially extracted": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
partiallyExtracted: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
"azure": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
"aws": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
|
|
|
tf: &stubTerraform{},
|
|
|
|
file: file.NewHandler(tc.fs),
|
|
|
|
workingDir: constants.TerraformIAMWorkingDir,
|
|
|
|
}
|
|
|
|
|
|
|
|
path := path.Join(tc.pathBase, strings.ToLower(tc.provider.String()))
|
|
|
|
err := c.PrepareWorkspace(path, tc.vars)
|
|
|
|
|
|
|
|
// Test case: Check if we can continue to create on an incomplete workspace.
|
|
|
|
if tc.partiallyExtracted {
|
|
|
|
require.NoError(c.file.Remove(filepath.Join(c.workingDir, "main.tf")))
|
|
|
|
err = c.PrepareWorkspace(path, tc.vars)
|
2022-11-15 08:00:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 03:22:29 -04:00
|
|
|
func TestCreateCluster(t *testing.T) {
|
2023-03-20 08:33:04 -04:00
|
|
|
newQEMUState := func() *tfjson.State {
|
|
|
|
workingState := tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{
|
2023-10-17 09:46:15 -04:00
|
|
|
"out_of_cluster_endpoint": {
|
2023-03-20 08:33:04 -04:00
|
|
|
Value: "192.0.2.100",
|
|
|
|
},
|
2023-10-17 09:46:15 -04:00
|
|
|
"in_cluster_endpoint": {
|
|
|
|
Value: "192.0.2.101",
|
|
|
|
},
|
2023-03-20 08:33:04 -04:00
|
|
|
"initSecret": {
|
|
|
|
Value: "initSecret",
|
|
|
|
},
|
|
|
|
"uid": {
|
|
|
|
Value: "12345abc",
|
|
|
|
},
|
2023-07-21 10:43:51 -04:00
|
|
|
"api_server_cert_sans": {
|
|
|
|
Value: []any{"192.0.2.100"},
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
"name": {
|
|
|
|
Value: "constell-12345abc",
|
|
|
|
},
|
2023-10-23 09:06:48 -04:00
|
|
|
"ip_cidr_nodes": {
|
|
|
|
Value: "192.0.2.103/32",
|
|
|
|
},
|
2023-03-20 08:33:04 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &workingState
|
|
|
|
}
|
|
|
|
newAzureState := func() *tfjson.State {
|
2022-09-26 09:52:31 -04:00
|
|
|
workingState := tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{
|
2023-10-17 09:46:15 -04:00
|
|
|
"out_of_cluster_endpoint": {
|
2022-09-26 09:52:31 -04:00
|
|
|
Value: "192.0.2.100",
|
|
|
|
},
|
2023-10-17 09:46:15 -04:00
|
|
|
"in_cluster_endpoint": {
|
|
|
|
Value: "192.0.2.101",
|
|
|
|
},
|
2022-11-26 13:44:34 -05:00
|
|
|
"initSecret": {
|
|
|
|
Value: "initSecret",
|
|
|
|
},
|
2023-01-19 04:41:07 -05:00
|
|
|
"uid": {
|
|
|
|
Value: "12345abc",
|
|
|
|
},
|
2023-03-20 08:33:04 -04:00
|
|
|
"attestationURL": {
|
|
|
|
Value: "https://12345.neu.attest.azure.net",
|
|
|
|
},
|
2023-07-21 10:43:51 -04:00
|
|
|
"api_server_cert_sans": {
|
|
|
|
Value: []any{"192.0.2.100"},
|
|
|
|
},
|
2023-08-01 02:40:44 -04:00
|
|
|
"user_assigned_identity_client_id": {
|
2023-07-31 04:53:05 -04:00
|
|
|
Value: "test_uami_id",
|
|
|
|
},
|
|
|
|
"resource_group": {
|
|
|
|
Value: "test_rg",
|
|
|
|
},
|
|
|
|
"subscription_id": {
|
|
|
|
Value: "test_subscription_id",
|
|
|
|
},
|
|
|
|
"network_security_group_name": {
|
|
|
|
Value: "test_nsg_name",
|
|
|
|
},
|
|
|
|
"loadbalancer_name": {
|
|
|
|
Value: "test_lb_name",
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
"name": {
|
|
|
|
Value: "constell-12345abc",
|
|
|
|
},
|
2023-10-23 09:06:48 -04:00
|
|
|
"ip_cidr_nodes": {
|
|
|
|
Value: "192.0.2.103/32",
|
|
|
|
},
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &workingState
|
|
|
|
}
|
2022-09-27 03:22:29 -04:00
|
|
|
qemuVars := &QEMUVariables{
|
2023-06-28 08:42:34 -04:00
|
|
|
Name: "name",
|
|
|
|
NodeGroups: map[string]QEMUNodeGroup{
|
|
|
|
"control-plane": {
|
|
|
|
Role: role.ControlPlane.TFString(),
|
|
|
|
DiskSize: 11,
|
|
|
|
CPUCount: 1,
|
|
|
|
MemorySize: 1024,
|
|
|
|
},
|
2022-09-27 03:22:29 -04:00
|
|
|
},
|
2023-06-28 08:42:34 -04:00
|
|
|
Machine: "q35",
|
2022-09-27 03:22:29 -04:00
|
|
|
ImagePath: "path",
|
|
|
|
ImageFormat: "format",
|
|
|
|
MetadataAPIImage: "api",
|
|
|
|
}
|
2022-09-26 09:52:31 -04:00
|
|
|
|
|
|
|
testCases := map[string]struct {
|
2022-12-07 05:48:54 -05:00
|
|
|
pathBase string
|
2022-09-26 09:52:31 -04:00
|
|
|
provider cloudprovider.Provider
|
2022-09-27 03:22:29 -04:00
|
|
|
vars Variables
|
2022-09-26 09:52:31 -04:00
|
|
|
tf *stubTerraform
|
|
|
|
fs afero.Fs
|
2023-03-20 08:33:04 -04:00
|
|
|
// expectedAttestationURL is the expected attestation URL to be returned by
|
|
|
|
// the Terraform client. It is declared in the test case because it is
|
|
|
|
// provider-specific.
|
|
|
|
expectedAttestationURL string
|
|
|
|
wantErr bool
|
2022-09-26 09:52:31 -04:00
|
|
|
}{
|
|
|
|
"works": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-09-26 09:52:31 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
2022-09-27 03:22:29 -04:00
|
|
|
vars: qemuVars,
|
2023-03-20 08:33:04 -04:00
|
|
|
tf: &stubTerraform{showState: newQEMUState()},
|
2022-09-27 03:22:29 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
|
|
|
"init fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-09-26 09:52:31 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
2022-11-15 08:00:44 -05:00
|
|
|
vars: qemuVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{initErr: assert.AnError},
|
2022-09-27 03:22:29 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
|
|
|
"apply fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-09-26 09:52:31 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
2022-09-27 03:22:29 -04:00
|
|
|
vars: qemuVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{applyErr: assert.AnError},
|
2022-09-27 03:22:29 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
|
|
|
"show fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-09-26 09:52:31 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
2022-09-27 03:22:29 -04:00
|
|
|
vars: qemuVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{showErr: assert.AnError},
|
2022-09-27 03:22:29 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
2023-04-14 08:15:07 -04:00
|
|
|
"set log fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-04-14 08:15:07 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{setLogErr: assert.AnError},
|
2023-04-14 08:15:07 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"set log path fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-04-14 08:15:07 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{setLogPathErr: assert.AnError},
|
2023-04-14 08:15:07 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2022-09-26 09:52:31 -04:00
|
|
|
"no ip": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-09-26 09:52:31 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
2022-09-27 03:22:29 -04:00
|
|
|
vars: qemuVars,
|
2022-09-26 09:52:31 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2022-09-27 03:22:29 -04:00
|
|
|
"ip has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2022-09-26 09:52:31 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
2022-09-27 03:22:29 -04:00
|
|
|
vars: qemuVars,
|
2022-09-26 09:52:31 -04:00
|
|
|
tf: &stubTerraform{
|
2022-09-27 03:22:29 -04:00
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"ip": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
2022-09-27 03:22:29 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
2022-09-26 09:52:31 -04:00
|
|
|
wantErr: true,
|
|
|
|
},
|
2023-01-19 04:41:07 -05:00
|
|
|
"no uid": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-01-19 04:41:07 -05:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"uid has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-01-19 04:41:07 -05:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"uid": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2023-10-09 07:04:29 -04:00
|
|
|
"name has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-10-09 07:04:29 -04:00
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
vars: qemuVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"name": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2023-03-20 08:33:04 -04:00
|
|
|
"working attestation url": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-03-20 08:33:04 -04:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: qemuVars, // works for mocking azure vars
|
|
|
|
tf: &stubTerraform{showState: newAzureState()},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
expectedAttestationURL: "https://12345.neu.attest.azure.net",
|
|
|
|
},
|
|
|
|
"no attestation url": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-03-20 08:33:04 -04:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: qemuVars, // works for mocking azure vars
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"attestation url has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-03-20 08:33:04 -04:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: qemuVars, // works for mocking azure vars
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"attestationURL": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2022-09-26 09:52:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2022-11-15 08:00:44 -05:00
|
|
|
require := require.New(t)
|
2022-09-26 09:52:31 -04:00
|
|
|
|
|
|
|
c := &Client{
|
2022-11-14 12:18:58 -05:00
|
|
|
tf: tc.tf,
|
|
|
|
file: file.NewHandler(tc.fs),
|
2023-08-04 07:53:51 -04:00
|
|
|
workingDir: "unittest",
|
2022-09-26 09:52:31 -04:00
|
|
|
}
|
|
|
|
|
2022-12-07 05:48:54 -05:00
|
|
|
path := path.Join(tc.pathBase, strings.ToLower(tc.provider.String()))
|
|
|
|
require.NoError(c.PrepareWorkspace(path, tc.vars))
|
2023-09-25 11:10:23 -04:00
|
|
|
infraState, err := c.ApplyCluster(context.Background(), tc.provider, LogLevelDebug)
|
2022-09-27 03:22:29 -04:00
|
|
|
|
2022-09-26 09:52:31 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
2023-09-25 11:10:23 -04:00
|
|
|
assert.Equal("192.0.2.100", infraState.ClusterEndpoint)
|
2023-10-17 04:35:54 -04:00
|
|
|
assert.Equal(state.HexBytes("initSecret"), infraState.InitSecret)
|
2023-09-25 11:10:23 -04:00
|
|
|
assert.Equal("12345abc", infraState.UID)
|
2023-10-17 09:46:15 -04:00
|
|
|
assert.Equal("192.0.2.101", infraState.InClusterEndpoint)
|
2023-10-23 09:06:48 -04:00
|
|
|
assert.Equal("192.0.2.103/32", infraState.IPCidrNode)
|
2023-07-31 04:53:05 -04:00
|
|
|
if tc.provider == cloudprovider.Azure {
|
2023-09-25 11:10:23 -04:00
|
|
|
assert.Equal(tc.expectedAttestationURL, infraState.Azure.AttestationURL)
|
2023-07-31 04:53:05 -04:00
|
|
|
}
|
2022-09-26 09:52:31 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 05:48:54 -05:00
|
|
|
func TestCreateIAM(t *testing.T) {
|
|
|
|
newTestState := func() *tfjson.State {
|
|
|
|
workingState := tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{
|
|
|
|
"sa_key": {
|
|
|
|
Value: "12345678_abcdefg",
|
|
|
|
},
|
|
|
|
"subscription_id": {
|
|
|
|
Value: "test_subscription_id",
|
|
|
|
},
|
|
|
|
"tenant_id": {
|
|
|
|
Value: "test_tenant_id",
|
|
|
|
},
|
|
|
|
"application_id": {
|
|
|
|
Value: "test_application_id",
|
|
|
|
},
|
|
|
|
"uami_id": {
|
|
|
|
Value: "test_uami_id",
|
|
|
|
},
|
|
|
|
"application_client_secret_value": {
|
|
|
|
Value: "test_application_client_secret_value",
|
|
|
|
},
|
|
|
|
"control_plane_instance_profile": {
|
|
|
|
Value: "test_control_plane_instance_profile",
|
|
|
|
},
|
|
|
|
"worker_nodes_instance_profile": {
|
|
|
|
Value: "test_worker_nodes_instance_profile",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &workingState
|
|
|
|
}
|
|
|
|
gcpVars := &GCPIAMVariables{
|
|
|
|
Project: "const-1234",
|
|
|
|
Region: "europe-west1",
|
|
|
|
Zone: "europe-west1-a",
|
|
|
|
ServiceAccountID: "const-test-case",
|
|
|
|
}
|
|
|
|
azureVars := &AzureIAMVariables{
|
2023-05-26 05:45:03 -04:00
|
|
|
Region: "westus",
|
|
|
|
ResourceGroup: "constell-test-rg",
|
2022-12-07 05:48:54 -05:00
|
|
|
}
|
|
|
|
awsVars := &AWSIAMVariables{
|
|
|
|
Region: "eu-east-2a",
|
|
|
|
Prefix: "test",
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
pathBase string
|
|
|
|
provider cloudprovider.Provider
|
|
|
|
vars Variables
|
|
|
|
tf *stubTerraform
|
|
|
|
fs afero.Fs
|
|
|
|
wantErr bool
|
|
|
|
want IAMOutput
|
|
|
|
}{
|
2023-04-14 08:15:07 -04:00
|
|
|
"set log fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2023-04-14 08:15:07 -04:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{setLogErr: assert.AnError},
|
2023-04-14 08:15:07 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"set log path fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2023-04-14 08:15:07 -04:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{setLogPathErr: assert.AnError},
|
2023-04-14 08:15:07 -04:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2022-12-07 05:48:54 -05:00
|
|
|
"gcp works": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
|
|
|
tf: &stubTerraform{showState: newTestState()},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
want: IAMOutput{GCP: GCPIAMOutput{SaKey: "12345678_abcdefg"}},
|
|
|
|
},
|
|
|
|
"gcp init fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{initErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"gcp apply fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{applyErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"gcp show fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{showErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"gcp no sa_key": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"gcp sa_key has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.GCP,
|
|
|
|
vars: gcpVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"sa_key": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"azure works": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
|
|
|
tf: &stubTerraform{showState: newTestState()},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
want: IAMOutput{Azure: AzureIAMOutput{
|
2023-05-26 05:45:03 -04:00
|
|
|
SubscriptionID: "test_subscription_id",
|
|
|
|
TenantID: "test_tenant_id",
|
|
|
|
UAMIID: "test_uami_id",
|
2022-12-07 05:48:54 -05:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
"azure init fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{initErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"azure apply fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{applyErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"azure show fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{showErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"azure no subscription_id": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"azure subscription_id has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.Azure,
|
|
|
|
vars: azureVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"subscription_id": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"aws works": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
|
|
|
tf: &stubTerraform{showState: newTestState()},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
want: IAMOutput{AWS: AWSIAMOutput{
|
|
|
|
ControlPlaneInstanceProfile: "test_control_plane_instance_profile",
|
|
|
|
WorkerNodeInstanceProfile: "test_worker_nodes_instance_profile",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
"aws init fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{initErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"aws apply fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{applyErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"aws show fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{showErr: assert.AnError},
|
2022-12-07 05:48:54 -05:00
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"aws no control_plane_instance_profile": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"azure control_plane_instance_profile has wrong type": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: path.Join(constants.TerraformEmbeddedDir, "iam"),
|
2022-12-07 05:48:54 -05:00
|
|
|
provider: cloudprovider.AWS,
|
|
|
|
vars: awsVars,
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{"control_plane_instance_profile": {Value: 42}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
|
|
|
tf: tc.tf,
|
|
|
|
file: file.NewHandler(tc.fs),
|
|
|
|
workingDir: constants.TerraformIAMWorkingDir,
|
|
|
|
}
|
|
|
|
|
|
|
|
path := path.Join(tc.pathBase, strings.ToLower(tc.provider.String()))
|
|
|
|
require.NoError(c.PrepareWorkspace(path, tc.vars))
|
2023-08-21 04:26:53 -04:00
|
|
|
IAMoutput, err := c.ApplyIAM(context.Background(), tc.provider, LogLevelDebug)
|
2022-12-07 05:48:54 -05:00
|
|
|
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(tc.want, IAMoutput)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:52:31 -04:00
|
|
|
func TestDestroyInstances(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
tf *stubTerraform
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"works": {
|
|
|
|
tf: &stubTerraform{},
|
|
|
|
},
|
|
|
|
"destroy fails": {
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{destroyErr: assert.AnError},
|
2023-04-14 08:15:07 -04:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"setLog fails": {
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{setLogErr: assert.AnError},
|
2023-04-14 08:15:07 -04:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"setLogPath fails": {
|
2023-08-09 09:25:59 -04:00
|
|
|
tf: &stubTerraform{setLogPathErr: assert.AnError},
|
2022-09-26 09:52:31 -04:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
2022-10-26 09:57:00 -04:00
|
|
|
tf: tc.tf,
|
2022-09-26 09:52:31 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 08:15:07 -04:00
|
|
|
err := c.Destroy(context.Background(), LogLevelDebug)
|
2022-09-26 09:52:31 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCleanupWorkspace(t *testing.T) {
|
|
|
|
someContent := []byte("some content")
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
provider cloudprovider.Provider
|
|
|
|
prepareFS func(file.Handler) error
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"files are cleaned up": {
|
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
prepareFS: func(f file.Handler) error {
|
2023-02-07 06:56:25 -05:00
|
|
|
if err := f.Write("terraform.tfvars", someContent); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := f.Write("terraform.tfstate", someContent); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return f.Write("terraform.tfstate.backup", someContent)
|
2022-09-26 09:52:31 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"no error if files do not exist": {
|
|
|
|
provider: cloudprovider.QEMU,
|
|
|
|
prepareFS: func(f file.Handler) error { return nil },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
file := file.NewHandler(afero.NewMemMapFs())
|
|
|
|
require.NoError(tc.prepareFS(file))
|
|
|
|
|
|
|
|
c := &Client{
|
2022-11-14 12:18:58 -05:00
|
|
|
file: file,
|
|
|
|
tf: &stubTerraform{},
|
2023-08-04 07:53:51 -04:00
|
|
|
workingDir: "unittest",
|
2022-09-26 09:52:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err := c.CleanUpWorkspace()
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
2022-11-14 12:18:58 -05:00
|
|
|
_, err = file.Stat(filepath.Join(c.workingDir, "terraform.tfvars"))
|
2022-09-26 09:52:31 -04:00
|
|
|
assert.ErrorIs(err, fs.ErrNotExist)
|
2022-11-14 12:18:58 -05:00
|
|
|
_, err = file.Stat(filepath.Join(c.workingDir, "terraform.tfstate"))
|
2022-09-26 09:52:31 -04:00
|
|
|
assert.ErrorIs(err, fs.ErrNotExist)
|
2022-11-14 12:18:58 -05:00
|
|
|
_, err = file.Stat(filepath.Join(c.workingDir, "terraform.tfstate.backup"))
|
2022-09-26 09:52:31 -04:00
|
|
|
assert.ErrorIs(err, fs.ErrNotExist)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-14 08:15:07 -04:00
|
|
|
func TestParseLogLevel(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
level string
|
|
|
|
want LogLevel
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"json": {
|
|
|
|
level: "json",
|
|
|
|
want: LogLevelJSON,
|
|
|
|
},
|
|
|
|
"trace": {
|
|
|
|
level: "trace",
|
|
|
|
want: LogLevelTrace,
|
|
|
|
},
|
|
|
|
"debug": {
|
|
|
|
level: "debug",
|
|
|
|
want: LogLevelDebug,
|
|
|
|
},
|
|
|
|
"info": {
|
|
|
|
level: "info",
|
|
|
|
want: LogLevelInfo,
|
|
|
|
},
|
|
|
|
"warn": {
|
|
|
|
level: "warn",
|
|
|
|
want: LogLevelWarn,
|
|
|
|
},
|
|
|
|
"error": {
|
|
|
|
level: "error",
|
|
|
|
want: LogLevelError,
|
|
|
|
},
|
|
|
|
"none": {
|
|
|
|
level: "none",
|
|
|
|
want: LogLevelNone,
|
|
|
|
},
|
|
|
|
"unknown": {
|
|
|
|
level: "unknown",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"empty": {
|
|
|
|
level: "",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
level, err := ParseLogLevel(tc.level)
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(tc.want, level)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLogLevelString(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
level LogLevel
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
"json": {
|
|
|
|
level: LogLevelJSON,
|
|
|
|
want: "JSON",
|
|
|
|
},
|
|
|
|
"trace": {
|
|
|
|
level: LogLevelTrace,
|
|
|
|
want: "TRACE",
|
|
|
|
},
|
|
|
|
"debug": {
|
|
|
|
level: LogLevelDebug,
|
|
|
|
want: "DEBUG",
|
|
|
|
},
|
|
|
|
"info": {
|
|
|
|
level: LogLevelInfo,
|
|
|
|
want: "INFO",
|
|
|
|
},
|
|
|
|
"warn": {
|
|
|
|
level: LogLevelWarn,
|
|
|
|
want: "WARN",
|
|
|
|
},
|
|
|
|
"error": {
|
|
|
|
level: LogLevelError,
|
|
|
|
want: "ERROR",
|
|
|
|
},
|
|
|
|
"none": {
|
|
|
|
level: LogLevelNone,
|
|
|
|
want: "",
|
|
|
|
},
|
|
|
|
"invalid int": {
|
|
|
|
level: LogLevel(-1),
|
|
|
|
want: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
assert.Equal(tc.want, tc.level.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 07:31:20 -04:00
|
|
|
func TestPlan(t *testing.T) {
|
|
|
|
someError := errors.New("some error")
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
pathBase string
|
|
|
|
tf *stubTerraform
|
|
|
|
fs afero.Fs
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"plan succeeds": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
},
|
|
|
|
"set log path fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
setLogPathErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"set log fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
setLogErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"plan fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
planJSONErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"init fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
initErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
|
|
|
file: file.NewHandler(tc.fs),
|
|
|
|
tf: tc.tf,
|
|
|
|
workingDir: tc.pathBase,
|
|
|
|
}
|
|
|
|
|
2023-08-04 07:53:51 -04:00
|
|
|
_, err := c.Plan(context.Background(), LogLevelDebug)
|
2023-05-22 07:31:20 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
require.Error(err)
|
|
|
|
} else {
|
|
|
|
require.NoError(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShowPlan(t *testing.T) {
|
|
|
|
someError := errors.New("some error")
|
|
|
|
testCases := map[string]struct {
|
|
|
|
pathBase string
|
|
|
|
tf *stubTerraform
|
|
|
|
fs afero.Fs
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"show plan succeeds": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
},
|
|
|
|
"set log path fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
setLogPathErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"set log fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
setLogErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"show plan file fails": {
|
2023-10-26 04:55:50 -04:00
|
|
|
pathBase: constants.TerraformEmbeddedDir,
|
2023-05-22 07:31:20 -04:00
|
|
|
tf: &stubTerraform{
|
|
|
|
showPlanFileErr: someError,
|
|
|
|
},
|
|
|
|
fs: afero.NewMemMapFs(),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
|
|
|
file: file.NewHandler(tc.fs),
|
|
|
|
tf: tc.tf,
|
|
|
|
workingDir: tc.pathBase,
|
|
|
|
}
|
|
|
|
|
2023-08-04 07:53:51 -04:00
|
|
|
err := c.ShowPlan(context.Background(), LogLevelDebug, bytes.NewBuffer(nil))
|
2023-05-22 07:31:20 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
require.Error(err)
|
|
|
|
} else {
|
|
|
|
require.NoError(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 09:25:59 -04:00
|
|
|
func TestShowIAM(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
tf *stubTerraform
|
|
|
|
csp cloudprovider.Provider
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"GCP success": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"sa_key": "key",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.GCP,
|
|
|
|
},
|
|
|
|
"GCP wrong data type": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"sa_key": map[string]any{},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.GCP,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"GCP missing key": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.GCP,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Azure success": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"subscription_id": "sub",
|
|
|
|
"tenant_id": "tenant",
|
|
|
|
"uami_id": "uami",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
},
|
|
|
|
"Azure wrong data type subscription_id": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"subscription_id": map[string]any{},
|
|
|
|
"tenant_id": "tenant",
|
|
|
|
"uami_id": "uami",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Azure wrong data type tenant_id": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"subscription_id": "sub",
|
|
|
|
"tenant_id": map[string]any{},
|
|
|
|
"uami_id": "uami",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Azure wrong data type uami_id": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"subscription_id": "sub",
|
|
|
|
"tenant_id": "tenant",
|
|
|
|
"uami_id": map[string]any{},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Azure missing uami_id": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"subscription_id": "sub",
|
|
|
|
"tenant_id": "tenant",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Azure missing tenant_id": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"subscription_id": "sub",
|
|
|
|
"uami_id": "uami",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Azure missing subscription_id": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"tenant_id": "tenant",
|
|
|
|
"uami_id": "uami",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.Azure,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"AWS success": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"control_plane_instance_profile": "profile",
|
|
|
|
"worker_nodes_instance_profile": "profile",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
},
|
|
|
|
"AWS wrong data type control_plane_instance_profile": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"control_plane_instance_profile": map[string]any{},
|
|
|
|
"worker_nodes_instance_profile": "profile",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"AWS wrong data type worker_nodes_instance_profile": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"control_plane_instance_profile": "profile",
|
|
|
|
"worker_nodes_instance_profile": map[string]any{},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"AWS missing control_plane_instance_profile": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"worker_nodes_instance_profile": "profile",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"AWS missing worker_nodes_instance_profile": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: getTfjsonState(map[string]any{
|
|
|
|
"control_plane_instance_profile": "profile",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Show fails": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showErr: assert.AnError,
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Show returns state with nil Value": {
|
|
|
|
tf: &stubTerraform{
|
|
|
|
showState: &tfjson.State{},
|
|
|
|
},
|
|
|
|
csp: cloudprovider.AWS,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
c := &Client{
|
|
|
|
tf: tc.tf,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := c.ShowIAM(context.Background(), tc.csp)
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:52:31 -04:00
|
|
|
type stubTerraform struct {
|
2023-05-22 07:31:20 -04:00
|
|
|
applyErr error
|
|
|
|
destroyErr error
|
|
|
|
initErr error
|
|
|
|
showErr error
|
|
|
|
setLogErr error
|
|
|
|
setLogPathErr error
|
|
|
|
planJSONErr error
|
|
|
|
showPlanFileErr error
|
2023-06-27 07:12:50 -04:00
|
|
|
stateMvErr error
|
2023-05-22 07:31:20 -04:00
|
|
|
showState *tfjson.State
|
2022-09-26 09:52:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubTerraform) Apply(context.Context, ...tfexec.ApplyOption) error {
|
|
|
|
return s.applyErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubTerraform) Destroy(context.Context, ...tfexec.DestroyOption) error {
|
|
|
|
return s.destroyErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubTerraform) Init(context.Context, ...tfexec.InitOption) error {
|
|
|
|
return s.initErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubTerraform) Show(context.Context, ...tfexec.ShowOption) (*tfjson.State, error) {
|
|
|
|
return s.showState, s.showErr
|
|
|
|
}
|
2023-04-14 08:15:07 -04:00
|
|
|
|
2023-05-22 07:31:20 -04:00
|
|
|
func (s *stubTerraform) Plan(context.Context, ...tfexec.PlanOption) (bool, error) {
|
|
|
|
return false, s.planJSONErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubTerraform) ShowPlanFileRaw(context.Context, string, ...tfexec.ShowOption) (string, error) {
|
|
|
|
return "", s.showPlanFileErr
|
|
|
|
}
|
|
|
|
|
2023-04-14 08:15:07 -04:00
|
|
|
func (s *stubTerraform) SetLog(_ string) error {
|
|
|
|
return s.setLogErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stubTerraform) SetLogPath(_ string) error {
|
|
|
|
return s.setLogPathErr
|
|
|
|
}
|
2023-06-27 07:12:50 -04:00
|
|
|
|
|
|
|
func (s *stubTerraform) StateMv(_ context.Context, _, _ string, _ ...tfexec.StateMvCmdOption) error {
|
|
|
|
return s.stateMvErr
|
|
|
|
}
|
2023-08-09 09:25:59 -04:00
|
|
|
|
|
|
|
func getTfjsonState(values map[string]any) *tfjson.State {
|
|
|
|
state := tfjson.State{
|
|
|
|
Values: &tfjson.StateValues{
|
|
|
|
Outputs: map[string]*tfjson.StateOutput{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for k, v := range values {
|
|
|
|
state.Values.Outputs[k] = &tfjson.StateOutput{Value: v}
|
|
|
|
}
|
|
|
|
return &state
|
|
|
|
}
|