-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/template: convert resources to data sources
The template resources don't actually need to retain any state, so they are good candidates to be data sources. This includes a few tweaks to the acceptance tests -- now configured to run as unit tests -- since it seems that they have been slightly broken for a while now. In particular, the "update" cases are no longer tested because updating is not a meaningful operation for a data source.
- Loading branch information
1 parent
a1021f3
commit caab819
Showing
11 changed files
with
122 additions
and
262 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
80 changes: 80 additions & 0 deletions
80
builtin/providers/template/datasource_cloudinit_config_test.go
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,80 @@ | ||
package template | ||
|
||
import ( | ||
"testing" | ||
|
||
r "github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestRender(t *testing.T) { | ||
testCases := []struct { | ||
ResourceBlock string | ||
Expected string | ||
}{ | ||
{ | ||
`data "template_cloudinit_config" "foo" { | ||
gzip = false | ||
base64_encode = false | ||
part { | ||
content_type = "text/x-shellscript" | ||
content = "baz" | ||
} | ||
}`, | ||
"Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY--\r\n", | ||
}, | ||
{ | ||
`data "template_cloudinit_config" "foo" { | ||
gzip = false | ||
base64_encode = false | ||
part { | ||
content_type = "text/x-shellscript" | ||
content = "baz" | ||
filename = "foobar.sh" | ||
} | ||
}`, | ||
"Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Disposition: attachment; filename=\"foobar.sh\"\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY--\r\n", | ||
}, | ||
{ | ||
`data "template_cloudinit_config" "foo" { | ||
gzip = false | ||
base64_encode = false | ||
part { | ||
content_type = "text/x-shellscript" | ||
content = "baz" | ||
} | ||
part { | ||
content_type = "text/x-shellscript" | ||
content = "ffbaz" | ||
} | ||
}`, | ||
"Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nffbaz\r\n--MIMEBOUNDARY--\r\n", | ||
}, | ||
} | ||
|
||
for _, tt := range testCases { | ||
r.UnitTest(t, r.TestCase{ | ||
Providers: testProviders, | ||
Steps: []r.TestStep{ | ||
r.TestStep{ | ||
Config: tt.ResourceBlock, | ||
Check: r.ComposeTestCheckFunc( | ||
r.TestCheckResourceAttr("data.template_cloudinit_config.foo", "rendered", tt.Expected), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
var testCloudInitConfig_basic = ` | ||
data "template_cloudinit_config" "config" { | ||
part { | ||
content_type = "text/x-shellscript" | ||
content = "baz" | ||
} | ||
}` | ||
|
||
var testCloudInitConfig_basic_expected = `Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY--\r\n` |
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
Oops, something went wrong.