-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add detach support which is compatible with hcl2 used for terraform 0.12 #45
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
713a356
Add test
btromanova 3deaa0f
Don't pass variable to a module if it doesn't require it
btromanova 0607675
Move test from integration to internal to speed up the execution
btromanova bed01b2
Smaller diff
btromanova 5e1f603
Get plan output with terraform 0.12
btromanova e42b365
Feedback: move StringVersionMatches from terraform package to test
btromanova 3aa637d
Add detach support which is compatible with hcl2 used for terraform 0.12
btromanova 64bb150
Review feedback
btromanova 618e7f2
Spaces -> tabs
btromanova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,16 @@ import ( | |
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDeleteTerraformBackendConfig(t *testing.T) { | ||
// Tests that backend part can be successfully removed from the config | ||
// written in HCL 1.0 language | ||
func TestDeleteTerraformBackendConfigWithHCL1(t *testing.T) { | ||
input := []byte(` | ||
terraform { | ||
backend "s3" {} | ||
} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
region = "${var.aws_region}" | ||
} | ||
|
||
module "codecommit" { | ||
|
@@ -44,13 +46,13 @@ terraform { | |
] | ||
}`) | ||
|
||
updatedConfig, err := deleteTerraformBackendConfig(input) | ||
updatedConfig, err := deleteTerraformBackendConfigWithHCL1(input) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, `terraform {} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
region = "${var.aws_region}" | ||
} | ||
|
||
module "codecommit" { | ||
|
@@ -66,3 +68,88 @@ module "codecommit" { | |
] | ||
}`, string(updatedConfig)) | ||
} | ||
|
||
// Tests that backend part can be successfully removed from the config | ||
// written in HCL 2.0 language | ||
func TestDeleteTerraformBackendConfigWithHCL2Success(t *testing.T) { | ||
tests := []struct { | ||
btromanova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
config string | ||
expected string | ||
}{ | ||
{ | ||
config: ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still looks weird. Is it because of a tabs/spaces mix? |
||
provider "aws"{ | ||
region = var.aws_region | ||
}`, | ||
expected: ` | ||
provider "aws"{ | ||
region = var.aws_region | ||
}`, | ||
}, | ||
{ | ||
config: ` | ||
terraform { | ||
version = "v0.12.6" | ||
backend "local" { | ||
path = "path" | ||
} | ||
key = "value" | ||
}`, | ||
expected: ` | ||
terraform { | ||
version = "v0.12.6" | ||
key = "value" | ||
}`, | ||
}, | ||
{ | ||
config: ` | ||
terraform {backend "s3" {}} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
}`, | ||
expected: ` | ||
terraform {} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
}`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
actual, err := deleteTerraformBackendConfigWithHCL2([]byte(tt.config)) | ||
assert.Equal(t, string(actual), tt.expected) | ||
assert.Nil(t, err) | ||
} | ||
} | ||
|
||
// Tests that trying to delete backend part from configs where | ||
// backend secions contains parenthesis fails. See comment on | ||
// deleteTerraformBackendConfigWithHCL2 for clarification. | ||
func TestDeleteTerraformBackendConfigWithHCL2Failure(t *testing.T) { | ||
tests := []struct { | ||
config string | ||
}{ | ||
{ | ||
config: ` | ||
terraform { | ||
backend "local" { | ||
path = "module-{{.environment}}" | ||
} | ||
}`, | ||
}, | ||
{ | ||
config: ` | ||
terraform { | ||
backend "concil" { | ||
map = {"key": "val"} | ||
} | ||
}`, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
_, err := deleteTerraformBackendConfigWithHCL2([]byte(tt.config)) | ||
assert.NotNil(t, err) | ||
} | ||
} |
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,3 @@ | ||
terraform { | ||
required_version = ">= 0.8" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to explicitly show that this is HCL 1.0