@@ -1759,7 +1759,6 @@ resource "test_object" "a" {
17591759 },
17601760
17611761 "unknown condition" : {
1762- toBeImplemented : true ,
17631762 module : map [string ]string {
17641763 "main.tf" : `
17651764variable "cond" {
@@ -1867,6 +1866,132 @@ resource "test_object" "a" {
18671866 }
18681867 },
18691868 },
1869+
1870+ "non-boolean unknown condition" : {
1871+ module : map [string ]string {
1872+ "main.tf" : `
1873+ variable "cond" {
1874+ type = number
1875+ }
1876+ action "test_unlinked" "hello" {}
1877+ resource "test_object" "a" {
1878+ lifecycle {
1879+ action_trigger {
1880+ events = [before_create]
1881+ condition = var.cond + 12
1882+ actions = [action.test_unlinked.hello]
1883+ }
1884+ }
1885+ }
1886+ ` ,
1887+ },
1888+ expectPlanActionCalled : false ,
1889+ planOpts : & PlanOpts {
1890+ Mode : plans .NormalMode ,
1891+ SetVariables : InputValues {
1892+ "cond" : & InputValue {
1893+ Value : cty .UnknownVal (cty .Number ),
1894+ SourceType : ValueFromCaller ,
1895+ },
1896+ },
1897+ },
1898+
1899+ expectPlanDiagnostics : func (m * configs.Config ) tfdiags.Diagnostics {
1900+ return tfdiags.Diagnostics {}.Append (& hcl.Diagnostic {
1901+ Severity : hcl .DiagError ,
1902+ Summary : "Incorrect value type" ,
1903+ Detail : "Invalid expression value: bool required, but have number." ,
1904+ Subject : & hcl.Range {
1905+ Filename : filepath .Join (m .Module .SourceDir , "main.tf" ),
1906+ Start : hcl.Pos {Line : 10 , Column : 19 , Byte : 186 },
1907+ End : hcl.Pos {Line : 10 , Column : 39 , Byte : 199 },
1908+ },
1909+ })
1910+ },
1911+ },
1912+
1913+ "using count in condition" : {
1914+ toBeImplemented : true ,
1915+ module : map [string ]string {
1916+ "main.tf" : `
1917+
1918+ action "test_unlinked" "hello" {}
1919+ action "test_unlinked" "world" {}
1920+
1921+ resource "test_object" "a" {
1922+ count = 2
1923+ name = "foo"
1924+ lifecycle {
1925+ action_trigger {
1926+ events = [before_create]
1927+ condition = count.index == 1
1928+ actions = [action.test_unlinked.hello]
1929+ }
1930+ action_trigger {
1931+ events = [before_create]
1932+ condition = count.index == 2
1933+ actions = [action.test_unlinked.world]
1934+ }
1935+ }
1936+ }
1937+ ` ,
1938+ },
1939+ expectPlanActionCalled : true ,
1940+
1941+ assertPlan : func (t * testing.T , p * plans.Plan ) {
1942+ if len (p .Changes .ActionInvocations ) != 1 {
1943+ t .Fatalf ("expected 1 actions in plan, got %d" , len (p .Changes .ActionInvocations ))
1944+ }
1945+ if p .Changes .ActionInvocations [0 ].Addr .String () != "action.test_unlinked.hello" {
1946+ t .Fatalf ("expected action.test_unlinked.hello, got %s" , p .Changes .ActionInvocations [0 ].Addr .String ())
1947+ }
1948+ at := p .Changes .ActionInvocations [0 ].ActionTrigger .(plans.LifecycleActionTrigger )
1949+ if ! at .TriggeringResourceAddr .Equal (mustResourceInstanceAddr ("test_object.a[1]" )) {
1950+ t .Fatalf ("expected test_object.a[1], got %s" , at .TriggeringResourceAddr .String ())
1951+ }
1952+ },
1953+ },
1954+ "using for_each in condition" : {
1955+ toBeImplemented : true ,
1956+ module : map [string ]string {
1957+ "main.tf" : `
1958+
1959+ action "test_unlinked" "hello" {}
1960+ action "test_unlinked" "world" {}
1961+
1962+ resource "test_object" "a" {
1963+ for_each = toset(["foo", "bar"])
1964+ name = "foo"
1965+ lifecycle {
1966+ action_trigger {
1967+ events = [before_create]
1968+ condition = for_each.key == "bar"
1969+ actions = [action.test_unlinked.hello]
1970+ }
1971+ action_trigger {
1972+ events = [before_create]
1973+ condition = for_each.key == "baz"
1974+ actions = [action.test_unlinked.world]
1975+ }
1976+ }
1977+ }
1978+ ` ,
1979+ },
1980+ expectPlanActionCalled : true ,
1981+
1982+ assertPlan : func (t * testing.T , p * plans.Plan ) {
1983+ if len (p .Changes .ActionInvocations ) != 1 {
1984+ t .Fatalf ("expected 1 actions in plan, got %d" , len (p .Changes .ActionInvocations ))
1985+ }
1986+ if p .Changes .ActionInvocations [0 ].Addr .String () != "action.test_unlinked.hello" {
1987+ t .Fatalf ("expected action.test_unlinked.hello, got %s" , p .Changes .ActionInvocations [0 ].Addr .String ())
1988+ }
1989+ at := p .Changes .ActionInvocations [0 ].ActionTrigger .(plans.LifecycleActionTrigger )
1990+ if ! at .TriggeringResourceAddr .Equal (mustResourceInstanceAddr (`test_object.a["bar"]` )) {
1991+ t .Fatalf (`expected test_object.a["bar"], got %s` , at .TriggeringResourceAddr .String ())
1992+ }
1993+ },
1994+ },
18701995 } {
18711996 t .Run (name , func (t * testing.T ) {
18721997 if tc .toBeImplemented {
0 commit comments