remove unused depends_on field and add test
The depends_on fields was deprecated during 0.12, and is no longer used. Add a roundtrip test for the create_before_destroy status.
This commit is contained in:
parent
23f5fc3e5a
commit
9fe87fe520
|
@ -42,11 +42,6 @@ type ResourceInstanceObject struct {
|
||||||
// destroy operations, we need to record the status to ensure a resource
|
// destroy operations, we need to record the status to ensure a resource
|
||||||
// removed from the config will still be destroyed in the same manner.
|
// removed from the config will still be destroyed in the same manner.
|
||||||
CreateBeforeDestroy bool
|
CreateBeforeDestroy bool
|
||||||
|
|
||||||
// DependsOn corresponds to the deprecated `depends_on` field in the state.
|
|
||||||
// This field contained the configuration `depends_on` values, and some of
|
|
||||||
// the references from within a single module.
|
|
||||||
DependsOn []addrs.Referenceable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectStatus represents the status of a RemoteObject.
|
// ObjectStatus represents the status of a RemoteObject.
|
||||||
|
|
|
@ -55,8 +55,6 @@ type ResourceInstanceObjectSrc struct {
|
||||||
Status ObjectStatus
|
Status ObjectStatus
|
||||||
Dependencies []addrs.ConfigResource
|
Dependencies []addrs.ConfigResource
|
||||||
CreateBeforeDestroy bool
|
CreateBeforeDestroy bool
|
||||||
// deprecated
|
|
||||||
DependsOn []addrs.Referenceable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode unmarshals the raw representation of the object attributes. Pass the
|
// Decode unmarshals the raw representation of the object attributes. Pass the
|
||||||
|
@ -89,7 +87,6 @@ func (os *ResourceInstanceObjectSrc) Decode(ty cty.Type) (*ResourceInstanceObjec
|
||||||
Value: val,
|
Value: val,
|
||||||
Status: os.Status,
|
Status: os.Status,
|
||||||
Dependencies: os.Dependencies,
|
Dependencies: os.Dependencies,
|
||||||
DependsOn: os.DependsOn,
|
|
||||||
Private: os.Private,
|
Private: os.Private,
|
||||||
CreateBeforeDestroy: os.CreateBeforeDestroy,
|
CreateBeforeDestroy: os.CreateBeforeDestroy,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -158,12 +158,6 @@ func (obj *ResourceInstanceObjectSrc) DeepCopy() *ResourceInstanceObjectSrc {
|
||||||
copy(dependencies, obj.Dependencies)
|
copy(dependencies, obj.Dependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dependsOn []addrs.Referenceable
|
|
||||||
if obj.DependsOn != nil {
|
|
||||||
dependsOn = make([]addrs.Referenceable, len(obj.DependsOn))
|
|
||||||
copy(dependsOn, obj.DependsOn)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ResourceInstanceObjectSrc{
|
return &ResourceInstanceObjectSrc{
|
||||||
Status: obj.Status,
|
Status: obj.Status,
|
||||||
SchemaVersion: obj.SchemaVersion,
|
SchemaVersion: obj.SchemaVersion,
|
||||||
|
@ -171,7 +165,6 @@ func (obj *ResourceInstanceObjectSrc) DeepCopy() *ResourceInstanceObjectSrc {
|
||||||
AttrsFlat: attrsFlat,
|
AttrsFlat: attrsFlat,
|
||||||
AttrsJSON: attrsJSON,
|
AttrsJSON: attrsJSON,
|
||||||
Dependencies: dependencies,
|
Dependencies: dependencies,
|
||||||
DependsOn: dependsOn,
|
|
||||||
CreateBeforeDestroy: obj.CreateBeforeDestroy,
|
CreateBeforeDestroy: obj.CreateBeforeDestroy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"version": 4,
|
||||||
|
"serial": 0,
|
||||||
|
"lineage": "f2968801-fa14-41ab-a044-224f3a4adf04",
|
||||||
|
"terraform_version": "0.12.0",
|
||||||
|
"outputs": {
|
||||||
|
"numbers": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "0,1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"module": "module.modA",
|
||||||
|
"mode": "managed",
|
||||||
|
"type": "null_resource",
|
||||||
|
"name": "resource",
|
||||||
|
"provider": "provider[\"registry.terraform.io/-/null\"]",
|
||||||
|
"instances": [
|
||||||
|
{
|
||||||
|
"schema_version": 0,
|
||||||
|
"attributes": {
|
||||||
|
"id": "4639265839606265182",
|
||||||
|
"triggers": {
|
||||||
|
"input": "test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"create_before_destroy": true,
|
||||||
|
"private": "bnVsbA=="
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
v4-cbd.in.tfstate
|
|
@ -370,7 +370,6 @@ func upgradeInstanceObjectV3ToV4(rsOld *resourceStateV2, isOld *instanceStateV2,
|
||||||
Status: status,
|
Status: status,
|
||||||
Deposed: string(deposedKey),
|
Deposed: string(deposedKey),
|
||||||
AttributesFlat: attributes,
|
AttributesFlat: attributes,
|
||||||
DependsOn: dependencies,
|
|
||||||
SchemaVersion: schemaVersion,
|
SchemaVersion: schemaVersion,
|
||||||
PrivateRaw: privateJSON,
|
PrivateRaw: privateJSON,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -172,34 +172,6 @@ func prepareStateV4(sV4 *stateV4) (*File, tfdiags.Diagnostics) {
|
||||||
obj.Private = raw
|
obj.Private = raw
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
// Allow both the deprecated `depends_on` and new
|
|
||||||
// `dependencies` to coexist for now so resources can be
|
|
||||||
// upgraded as they are refreshed.
|
|
||||||
depsRaw := isV4.DependsOn
|
|
||||||
deps := make([]addrs.Referenceable, 0, len(depsRaw))
|
|
||||||
for _, depRaw := range depsRaw {
|
|
||||||
ref, refDiags := addrs.ParseRefStr(depRaw)
|
|
||||||
diags = diags.Append(refDiags)
|
|
||||||
if refDiags.HasErrors() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(ref.Remaining) != 0 {
|
|
||||||
diags = diags.Append(tfdiags.Sourceless(
|
|
||||||
tfdiags.Error,
|
|
||||||
"Invalid resource instance metadata in state",
|
|
||||||
fmt.Sprintf("Instance %s declares dependency on %q, which is not a reference to a dependable object.", instAddr.Absolute(moduleAddr), depRaw),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
if ref.Subject == nil {
|
|
||||||
// Should never happen
|
|
||||||
panic(fmt.Sprintf("parsing dependency %q for instance %s returned a nil address", depRaw, instAddr.Absolute(moduleAddr)))
|
|
||||||
}
|
|
||||||
deps = append(deps, ref.Subject)
|
|
||||||
}
|
|
||||||
obj.DependsOn = deps
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
depsRaw := isV4.Dependencies
|
depsRaw := isV4.Dependencies
|
||||||
deps := make([]addrs.ConfigResource, 0, len(depsRaw))
|
deps := make([]addrs.ConfigResource, 0, len(depsRaw))
|
||||||
|
@ -463,11 +435,6 @@ func appendInstanceObjectStateV4(rs *states.Resource, is *states.ResourceInstanc
|
||||||
deps[i] = depAddr.String()
|
deps[i] = depAddr.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
depOn := make([]string, len(obj.DependsOn))
|
|
||||||
for i, depAddr := range obj.DependsOn {
|
|
||||||
depOn[i] = depAddr.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
var rawKey interface{}
|
var rawKey interface{}
|
||||||
switch tk := key.(type) {
|
switch tk := key.(type) {
|
||||||
case addrs.IntKey:
|
case addrs.IntKey:
|
||||||
|
@ -493,7 +460,6 @@ func appendInstanceObjectStateV4(rs *states.Resource, is *states.ResourceInstanc
|
||||||
AttributesRaw: obj.AttrsJSON,
|
AttributesRaw: obj.AttrsJSON,
|
||||||
PrivateRaw: privateRaw,
|
PrivateRaw: privateRaw,
|
||||||
Dependencies: deps,
|
Dependencies: deps,
|
||||||
DependsOn: depOn,
|
|
||||||
CreateBeforeDestroy: obj.CreateBeforeDestroy,
|
CreateBeforeDestroy: obj.CreateBeforeDestroy,
|
||||||
}), diags
|
}), diags
|
||||||
}
|
}
|
||||||
|
@ -545,7 +511,6 @@ type instanceObjectStateV4 struct {
|
||||||
PrivateRaw []byte `json:"private,omitempty"`
|
PrivateRaw []byte `json:"private,omitempty"`
|
||||||
|
|
||||||
Dependencies []string `json:"dependencies,omitempty"`
|
Dependencies []string `json:"dependencies,omitempty"`
|
||||||
DependsOn []string `json:"depends_on,omitempty"`
|
|
||||||
|
|
||||||
CreateBeforeDestroy bool `json:"create_before_destroy"`
|
CreateBeforeDestroy bool `json:"create_before_destroy"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue