|
|
|
|
@ -341,43 +341,26 @@ func TestApply_error(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
var lock sync.Mutex
|
|
|
|
|
errored := false
|
|
|
|
|
p.ApplyFn = func(info *terraform.InstanceInfo, s *terraform.InstanceState, d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
|
|
|
|
|
p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
|
|
|
|
lock.Lock()
|
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
|
|
|
|
|
if !errored {
|
|
|
|
|
errored = true
|
|
|
|
|
return nil, fmt.Errorf("error")
|
|
|
|
|
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newState := &terraform.InstanceState{
|
|
|
|
|
ID: "foo",
|
|
|
|
|
Attributes: map[string]string{},
|
|
|
|
|
}
|
|
|
|
|
newState.Attributes["id"] = newState.ID
|
|
|
|
|
if ad, ok := d.Attributes["ami"]; ok {
|
|
|
|
|
newState.Attributes["ami"] = ad.New
|
|
|
|
|
}
|
|
|
|
|
if ad, ok := d.Attributes["error"]; ok {
|
|
|
|
|
newState.Attributes["error"] = ad.New
|
|
|
|
|
}
|
|
|
|
|
return newState, nil
|
|
|
|
|
s := req.PlannedState.AsValueMap()
|
|
|
|
|
s["id"] = cty.StringVal("foo")
|
|
|
|
|
|
|
|
|
|
resp.NewState = cty.ObjectVal(s)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
p.DiffFn = func(info *terraform.InstanceInfo, s *terraform.InstanceState, rc *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
|
|
|
|
ret := &terraform.InstanceDiff{
|
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{},
|
|
|
|
|
}
|
|
|
|
|
if new, ok := rc.Get("ami"); ok {
|
|
|
|
|
ret.Attributes["ami"] = &terraform.ResourceAttrDiff{
|
|
|
|
|
New: new.(string),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if new, ok := rc.Get("error"); ok {
|
|
|
|
|
ret.Attributes["error"] = &terraform.ResourceAttrDiff{
|
|
|
|
|
New: fmt.Sprintf("%t", new.(bool)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret, nil
|
|
|
|
|
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
|
|
|
|
s := req.ProposedNewState.AsValueMap()
|
|
|
|
|
s["id"] = cty.UnknownVal(cty.String)
|
|
|
|
|
resp.PlannedState = cty.ObjectVal(s)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
p.GetSchemaReturn = &terraform.ProviderSchema{
|
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
|
|
|
@ -902,25 +885,13 @@ func TestApply_shutdown(t *testing.T) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.DiffFn = func(
|
|
|
|
|
*terraform.InstanceInfo,
|
|
|
|
|
*terraform.InstanceState,
|
|
|
|
|
*terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
|
|
|
|
return &terraform.InstanceDiff{
|
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
|
"ami": &terraform.ResourceAttrDiff{
|
|
|
|
|
New: "bar",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
|
|
|
|
resp.PlannedState = req.ProposedNewState
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var once sync.Once
|
|
|
|
|
p.ApplyFn = func(
|
|
|
|
|
*terraform.InstanceInfo,
|
|
|
|
|
*terraform.InstanceState,
|
|
|
|
|
*terraform.InstanceDiff) (*terraform.InstanceState, error) {
|
|
|
|
|
|
|
|
|
|
p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
|
|
|
|
// only cancel once
|
|
|
|
|
once.Do(func() {
|
|
|
|
|
shutdownCh <- struct{}{}
|
|
|
|
|
@ -934,12 +905,8 @@ func TestApply_shutdown(t *testing.T) {
|
|
|
|
|
// canceled.
|
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
return &terraform.InstanceState{
|
|
|
|
|
ID: "foo",
|
|
|
|
|
Attributes: map[string]string{
|
|
|
|
|
"ami": "2",
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
resp.NewState = req.PlannedState
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.GetSchemaReturn = &terraform.ProviderSchema{
|
|
|
|
|
|