@@ -199,6 +199,80 @@ func TestResourceBuilder_new(t *testing.T) {
199199 }
200200}
201201
202+ func TestResourceBuilder_preProcess (t * testing.T ) {
203+ rb := & ResourceBuilder {
204+ Attrs : map [string ]AttrType {
205+ "foo" : AttrTypeCreate ,
206+ },
207+
208+ PreProcess : map [string ]PreProcessFunc {
209+ "foo" : func (string ) string {
210+ return "bar"
211+ },
212+ },
213+ }
214+
215+ state := & terraform.ResourceState {}
216+ c := testConfig (t , map [string ]interface {}{
217+ "foo" : "foo" ,
218+ }, nil )
219+
220+ diff , err := rb .Diff (state , c )
221+ if err != nil {
222+ t .Fatalf ("err: %s" , err )
223+ }
224+ if diff == nil {
225+ t .Fatal ("diff shold not be nil" )
226+ }
227+
228+ actual := testResourceDiffStr (diff )
229+ expected := testRBPreProcessDiff
230+ if actual != expected {
231+ t .Fatalf ("bad: %s" , actual )
232+ }
233+
234+ actual = diff .Attributes ["foo" ].NewExtra .(string )
235+ expected = "foo"
236+ if actual != expected {
237+ t .Fatalf ("bad: %#v" , actual )
238+ }
239+ }
240+
241+ func TestResourceBuilder_preProcessUnknown (t * testing.T ) {
242+ rb := & ResourceBuilder {
243+ Attrs : map [string ]AttrType {
244+ "foo" : AttrTypeCreate ,
245+ },
246+
247+ PreProcess : map [string ]PreProcessFunc {
248+ "foo" : func (string ) string {
249+ return "bar"
250+ },
251+ },
252+ }
253+
254+ state := & terraform.ResourceState {}
255+ c := testConfig (t , map [string ]interface {}{
256+ "foo" : "${var.unknown}" ,
257+ }, map [string ]string {
258+ "var.unknown" : config .UnknownVariableValue ,
259+ })
260+
261+ diff , err := rb .Diff (state , c )
262+ if err != nil {
263+ t .Fatalf ("err: %s" , err )
264+ }
265+ if diff == nil {
266+ t .Fatal ("diff shold not be nil" )
267+ }
268+
269+ actual := testResourceDiffStr (diff )
270+ expected := testRBPreProcessUnknownDiff
271+ if actual != expected {
272+ t .Fatalf ("bad: %s" , actual )
273+ }
274+ }
275+
202276func TestResourceBuilder_requiresNew (t * testing.T ) {
203277 rb := & ResourceBuilder {
204278 ComputedAttrs : []string {"private_ip" },
@@ -338,6 +412,14 @@ const testRBNewDiff = `UPDATE
338412 OUT private_ip: "" => "<computed>"
339413`
340414
415+ const testRBPreProcessDiff = `CREATE
416+ IN foo: "" => "bar" (forces new resource)
417+ `
418+
419+ const testRBPreProcessUnknownDiff = `CREATE
420+ IN foo: "" => "${var.unknown}" (forces new resource)
421+ `
422+
341423const testRBRequiresNewDiff = `CREATE
342424 IN ami: "foo" => "bar" (forces new resource)
343425 OUT private_ip: "127.0.0.1" => "<computed>"
0 commit comments