-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from hazelops/fix/deprecate-template-provider
Deprecate template provider
- Loading branch information
Showing
7 changed files
with
213 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package test | ||
|
||
import ( | ||
//"github.com/gruntwork-io/terratest/modules/random" | ||
"fmt" | ||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure" | ||
"github.com/stretchr/testify/assert" | ||
"io" | ||
"os" | ||
//"strings" | ||
"testing" | ||
) | ||
|
||
func CopyFileCompleteWorkerEc2(src, dst string) (err error) { | ||
sfi, err := os.Stat(src) | ||
if err != nil { | ||
return | ||
} | ||
if !sfi.Mode().IsRegular() { | ||
// cannot copy non-regular files (e.g., directories, | ||
// symlinks, devices, etc.) | ||
return fmt.Errorf("CopyFile: non-regular source file %s (%q)", sfi.Name(), sfi.Mode().String()) | ||
} | ||
dfi, err := os.Stat(dst) | ||
if err != nil { | ||
if !os.IsNotExist(err) { | ||
return | ||
} | ||
} else { | ||
if !(dfi.Mode().IsRegular()) { | ||
return fmt.Errorf("CopyFile: non-regular destination file %s (%q)", dfi.Name(), dfi.Mode().String()) | ||
} | ||
if os.SameFile(sfi, dfi) { | ||
return | ||
} | ||
} | ||
if err = os.Link(src, dst); err == nil { | ||
return | ||
} | ||
err = copyFileContentsCompleteWorkerEc2(src, dst) | ||
return | ||
} | ||
|
||
func copyFileContentsCompleteWorkerEc2(src, dst string) (err error) { | ||
in, err := os.Open(src) | ||
if err != nil { | ||
return | ||
} | ||
defer in.Close() | ||
out, err := os.Create(dst) | ||
if err != nil { | ||
return | ||
} | ||
defer func() { | ||
cerr := out.Close() | ||
if err == nil { | ||
err = cerr | ||
} | ||
}() | ||
if _, err = io.Copy(out, in); err != nil { | ||
return | ||
} | ||
err = out.Sync() | ||
return | ||
} | ||
|
||
func cleanupExamplesWorkerEc2(t *testing.T, terraformOptions *terraform.Options, tempTestFolder string) { | ||
terraform.Destroy(t, terraformOptions) | ||
os.RemoveAll(tempTestFolder) | ||
} | ||
|
||
// Test the Terraform module in examples/complete using Terratest. | ||
func TestExamplesWorkerEc2(t *testing.T) { | ||
t.Parallel() | ||
// randID := strings.ToLower(random.UniqueId()) | ||
// attributes := []string{randID} | ||
|
||
rootFolder := "../" | ||
terraformFolderRelativeToRoot := "examples/complete-worker-ec2" | ||
|
||
tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) | ||
fullRootPath := rootFolder + terraformFolderRelativeToRoot | ||
|
||
// Copy terraform.tfvars | ||
fmt.Printf("Copying %s to %s\n", fullRootPath+"/terraform.tfvars", tempTestFolder+"/terraform.tfvars") | ||
err := CopyFileCompleteWorkerEc2(fullRootPath+"/terraform.tfvars", tempTestFolder+"/terraform.tfvars") | ||
if err != nil { | ||
fmt.Printf("CopyFile failed %q\n", err) | ||
} else { | ||
fmt.Printf("CopyFile succeeded\n") | ||
} | ||
dir, _ := os.ReadDir(tempTestFolder) | ||
for _, d := range dir { | ||
t.Log(d.Name()) | ||
} | ||
varFiles := []string{tempTestFolder + "/terraform.tfvars"} | ||
|
||
terraformOptions := &terraform.Options{ | ||
// The path to where our Terraform code is located | ||
TerraformDir: tempTestFolder, | ||
Upgrade: true, | ||
|
||
// Variables to pass to our Terraform code using -var-file options | ||
VarFiles: varFiles, | ||
/*Vars: map[string]interface{}{ | ||
"attributes": attributes, | ||
}, | ||
*/ | ||
} | ||
|
||
// At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer cleanupExamplesWorkerEc2(t, terraformOptions, tempTestFolder) | ||
|
||
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors | ||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
// Run `terraform output` to get the value of an output variable | ||
vpcCidr := terraform.Output(t, terraformOptions, "vpc_cidr") | ||
// Verify we're getting back the outputs we expect | ||
assert.Equal(t, "10.4.0.0/16", vpcCidr) | ||
|
||
// Run `terraform output` to get the value of an output variable | ||
privateSubnetCidrs := terraform.OutputList(t, terraformOptions, "private_subnet_cidrs") | ||
// Verify we're getting back the outputs we expect | ||
assert.Equal(t, []string{"10.4.20.0/23"}, privateSubnetCidrs) | ||
|
||
// Run `terraform output` to get the value of an output variable | ||
cloudWatchLogGroup := terraform.Output(t, terraformOptions, "cloudwatch_log_group") | ||
// Verify we're getting back the outputs we expect | ||
assert.Equal(t, "examples2-complete-worker-ec2", cloudWatchLogGroup) | ||
|
||
// Run `terraform output` to get the value of an output variable | ||
ecsClusterName := terraform.Output(t, terraformOptions, "ecs_cluster_name") | ||
// Verify we're getting back the outputs we expect | ||
assert.Equal(t, "examples2-tftest-complete-worker-ec2", ecsClusterName) | ||
|
||
/* | ||
// Run `terraform output` to get the value of an output variable | ||
proxyEndpoint := terraform.Output(t, terraformOptions, "proxy_endpoint") | ||
// Verify we're getting back the outputs we expect | ||
assert.Contains(t, proxyEndpoint, "eg-test-rds-proxy-"+randID) | ||
// Run `terraform output` to get the value of an output variable | ||
proxyTargetEndpoint := terraform.Output(t, terraformOptions, "proxy_target_endpoint") | ||
instanceAddress := terraform.Output(t, terraformOptions, "instance_address") | ||
// Verify we're getting back the outputs we expect | ||
assert.Equal(t, proxyTargetEndpoint, instanceAddress) | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,5 @@ terraform { | |
aws = { | ||
source = "hashicorp/aws" | ||
} | ||
template = { | ||
source = "hashicorp/template" | ||
} | ||
} | ||
} |