Add tokens.StackName (#14487)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-15 07:44:54 +00:00
|
|
|
// Copyright 2016-2023, Pulumi Corporation.
|
2018-10-15 16:52:55 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package edit
|
|
|
|
|
|
|
|
import (
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/graph"
|
2023-12-22 12:28:41 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
2023-06-28 16:02:04 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/slice"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
|
2018-10-15 16:52:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// OperationFunc is the type of functions that edit resources within a snapshot. The edits are made in-place to the
|
|
|
|
// given snapshot and pertain to the specific passed-in resource.
|
|
|
|
type OperationFunc func(*deploy.Snapshot, *resource.State) error
|
|
|
|
|
2022-10-26 20:34:53 +00:00
|
|
|
// DeleteResource deletes a given resource from the snapshot, if it is possible to do so.
|
|
|
|
//
|
|
|
|
// If targetDependents is true, dependents will also be deleted. Otherwise an error
|
|
|
|
// instance of `ResourceHasDependenciesError` will be returned.
|
|
|
|
//
|
|
|
|
// If non-nil, onProtected will be called on all protected resources planed for deletion.
|
|
|
|
//
|
|
|
|
// If a resource is marked protected after onProtected is called, an error instance of
|
|
|
|
// `ResourceHasDependenciesError` will be returned.
|
|
|
|
func DeleteResource(
|
|
|
|
snapshot *deploy.Snapshot, condemnedRes *resource.State,
|
|
|
|
onProtected func(*resource.State) error, targetDependents bool,
|
|
|
|
) error {
|
2023-02-17 18:46:23 +00:00
|
|
|
contract.Requiref(snapshot != nil, "snapshot", "must not be nil")
|
|
|
|
contract.Requiref(condemnedRes != nil, "condemnedRes", "must not be nil")
|
2018-10-15 16:52:55 +00:00
|
|
|
|
2022-10-26 20:34:53 +00:00
|
|
|
handleProtected := func(res *resource.State) error {
|
|
|
|
if !res.Protect {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
if onProtected != nil {
|
|
|
|
err = onProtected(res)
|
|
|
|
}
|
|
|
|
if err == nil && res.Protect {
|
|
|
|
err = ResourceProtectedError{res}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := handleProtected(condemnedRes); err != nil {
|
|
|
|
return err
|
2018-10-15 16:52:55 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 18:31:22 +00:00
|
|
|
var numSameURN int
|
|
|
|
for _, res := range snapshot.Resources {
|
|
|
|
if res.URN != condemnedRes.URN {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
numSameURN++
|
2022-10-26 20:34:53 +00:00
|
|
|
}
|
2023-02-08 18:31:22 +00:00
|
|
|
isUniqueURN := numSameURN <= 1
|
|
|
|
|
State: fix panic when deleting non-unique Provider (#15322)
# Description
In
https://github.com/pulumi/pulumi/commit/30f59eb30a9b519766aa0e3d3e463a2b4667466b,
we made sure that we
don't delete multiple resources, when a user is prompted to choose
between multiple resources with the same URN.
If there are non-unique URNs, we currently assume that we can just go
ahead and delete it, as there's still another resource that will
fulfill the requirements.
However that is not true if the dependent is a provider. Providers
are identified by a {URN, ID} tuple. Therefore even though after the
deletion of a provider with a specific URN there's still another one
with the same URN left, this is not good enough to fulfill the
dependency requirements.
If we don't have a unique URN, check again to make sure there's no
provider dependency on the condemned resource. If there is one, we
either error out, or delete the dependencies depending on the options
passed in.
Note that I haven't managed to reproduce this by just issuing pulumi
commands, but I did by editing the state in a way to reproduce the same
issue.
One unanswered question for me is how the deleted cluster in the
original issue ended up lingering in the state. While this PR fixes the
panic, and will make it easier for the user to actually delete the
cluster from the state (it's going to suggest `--target-dependents`
which will do the right thing), it doesn't address that bit.
Fixes https://github.com/pulumi/pulumi/issues/15166
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-02-05 16:21:38 +00:00
|
|
|
deleteSet := make(map[resource.URN][]*resource.State)
|
|
|
|
dg := graph.NewDependencyGraph(snapshot.Resources)
|
|
|
|
|
|
|
|
deps := dg.OnlyDependsOn(condemnedRes)
|
|
|
|
if len(deps) != 0 {
|
|
|
|
if !targetDependents {
|
|
|
|
return ResourceHasDependenciesError{Condemned: condemnedRes, Dependencies: deps}
|
|
|
|
}
|
|
|
|
for _, dep := range deps {
|
|
|
|
if err := handleProtected(dep); err != nil {
|
|
|
|
return err
|
2022-10-26 20:34:53 +00:00
|
|
|
}
|
State: fix panic when deleting non-unique Provider (#15322)
# Description
In
https://github.com/pulumi/pulumi/commit/30f59eb30a9b519766aa0e3d3e463a2b4667466b,
we made sure that we
don't delete multiple resources, when a user is prompted to choose
between multiple resources with the same URN.
If there are non-unique URNs, we currently assume that we can just go
ahead and delete it, as there's still another resource that will
fulfill the requirements.
However that is not true if the dependent is a provider. Providers
are identified by a {URN, ID} tuple. Therefore even though after the
deletion of a provider with a specific URN there's still another one
with the same URN left, this is not good enough to fulfill the
dependency requirements.
If we don't have a unique URN, check again to make sure there's no
provider dependency on the condemned resource. If there is one, we
either error out, or delete the dependencies depending on the options
passed in.
Note that I haven't managed to reproduce this by just issuing pulumi
commands, but I did by editing the state in a way to reproduce the same
issue.
One unanswered question for me is how the deleted cluster in the
original issue ended up lingering in the state. While this PR fixes the
panic, and will make it easier for the user to actually delete the
cluster from the state (it's going to suggest `--target-dependents`
which will do the right thing), it doesn't address that bit.
Fixes https://github.com/pulumi/pulumi/issues/15166
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-02-05 16:21:38 +00:00
|
|
|
deleteSet[dep.URN] = append(deleteSet[dep.URN], dep)
|
2022-10-26 20:34:53 +00:00
|
|
|
}
|
2018-10-15 16:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no resources that depend on condemnedRes, iterate through the snapshot and keep everything that's
|
|
|
|
// not condemnedRes.
|
2023-06-28 16:02:04 +00:00
|
|
|
newSnapshot := slice.Prealloc[*resource.State](len(snapshot.Resources))
|
2018-10-15 16:52:55 +00:00
|
|
|
var children []*resource.State
|
State: fix panic when deleting non-unique Provider (#15322)
# Description
In
https://github.com/pulumi/pulumi/commit/30f59eb30a9b519766aa0e3d3e463a2b4667466b,
we made sure that we
don't delete multiple resources, when a user is prompted to choose
between multiple resources with the same URN.
If there are non-unique URNs, we currently assume that we can just go
ahead and delete it, as there's still another resource that will
fulfill the requirements.
However that is not true if the dependent is a provider. Providers
are identified by a {URN, ID} tuple. Therefore even though after the
deletion of a provider with a specific URN there's still another one
with the same URN left, this is not good enough to fulfill the
dependency requirements.
If we don't have a unique URN, check again to make sure there's no
provider dependency on the condemned resource. If there is one, we
either error out, or delete the dependencies depending on the options
passed in.
Note that I haven't managed to reproduce this by just issuing pulumi
commands, but I did by editing the state in a way to reproduce the same
issue.
One unanswered question for me is how the deleted cluster in the
original issue ended up lingering in the state. While this PR fixes the
panic, and will make it easier for the user to actually delete the
cluster from the state (it's going to suggest `--target-dependents`
which will do the right thing), it doesn't address that bit.
Fixes https://github.com/pulumi/pulumi/issues/15166
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-02-05 16:21:38 +00:00
|
|
|
search:
|
2018-10-15 16:52:55 +00:00
|
|
|
for _, res := range snapshot.Resources {
|
2023-02-08 18:31:22 +00:00
|
|
|
if res == condemnedRes {
|
|
|
|
// Skip condemned resource.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
State: fix panic when deleting non-unique Provider (#15322)
# Description
In
https://github.com/pulumi/pulumi/commit/30f59eb30a9b519766aa0e3d3e463a2b4667466b,
we made sure that we
don't delete multiple resources, when a user is prompted to choose
between multiple resources with the same URN.
If there are non-unique URNs, we currently assume that we can just go
ahead and delete it, as there's still another resource that will
fulfill the requirements.
However that is not true if the dependent is a provider. Providers
are identified by a {URN, ID} tuple. Therefore even though after the
deletion of a provider with a specific URN there's still another one
with the same URN left, this is not good enough to fulfill the
dependency requirements.
If we don't have a unique URN, check again to make sure there's no
provider dependency on the condemned resource. If there is one, we
either error out, or delete the dependencies depending on the options
passed in.
Note that I haven't managed to reproduce this by just issuing pulumi
commands, but I did by editing the state in a way to reproduce the same
issue.
One unanswered question for me is how the deleted cluster in the
original issue ended up lingering in the state. While this PR fixes the
panic, and will make it easier for the user to actually delete the
cluster from the state (it's going to suggest `--target-dependents`
which will do the right thing), it doesn't address that bit.
Fixes https://github.com/pulumi/pulumi/issues/15166
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
---------
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2024-02-05 16:21:38 +00:00
|
|
|
for _, v := range deleteSet[res.URN] {
|
|
|
|
if v == res {
|
|
|
|
continue search
|
|
|
|
}
|
2023-02-08 18:31:22 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 20:34:53 +00:00
|
|
|
// While iterating, keep track of the set of resources that are parented to our
|
|
|
|
// condemned resource. This acts as a check on DependingOn, preventing a bug from
|
|
|
|
// introducing state corruption.
|
2023-02-08 18:31:22 +00:00
|
|
|
if res.Parent == condemnedRes.URN {
|
2018-10-15 16:52:55 +00:00
|
|
|
children = append(children, res)
|
|
|
|
}
|
|
|
|
|
2023-02-08 18:31:22 +00:00
|
|
|
newSnapshot = append(newSnapshot, res)
|
|
|
|
|
2018-10-15 16:52:55 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 18:31:22 +00:00
|
|
|
// If condemnedRes is unique and there exists a resource that is the child of condemnedRes,
|
|
|
|
// we can't delete it.
|
|
|
|
contract.Assertf(!isUniqueURN || len(children) == 0, "unexpected children in resource dependency list")
|
2018-10-15 16:52:55 +00:00
|
|
|
|
|
|
|
// Otherwise, we're good to go. Writing the new resource list into the snapshot persists the mutations that we have
|
|
|
|
// made above.
|
|
|
|
snapshot.Resources = newSnapshot
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnprotectResource unprotects a resource.
|
|
|
|
func UnprotectResource(_ *deploy.Snapshot, res *resource.State) error {
|
|
|
|
res.Protect = false
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-11 06:13:54 +00:00
|
|
|
// LocateResource returns all resources in the given snapshot that have the given URN.
|
2018-10-15 16:52:55 +00:00
|
|
|
func LocateResource(snap *deploy.Snapshot, urn resource.URN) []*resource.State {
|
2020-10-11 06:13:54 +00:00
|
|
|
// If there is no snapshot then return no resources
|
|
|
|
if snap == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-10-15 16:52:55 +00:00
|
|
|
|
|
|
|
var resources []*resource.State
|
|
|
|
for _, res := range snap.Resources {
|
|
|
|
if res.URN == urn {
|
|
|
|
resources = append(resources, res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resources
|
|
|
|
}
|
2019-03-11 19:18:55 +00:00
|
|
|
|
2023-12-22 12:28:41 +00:00
|
|
|
// RenameStack changes the `stackName` component of every URN in a deployment. In addition, it rewrites the name of
|
2019-09-26 22:23:09 +00:00
|
|
|
// the root Stack resource itself. May optionally change the project/package name as well.
|
2023-12-22 12:28:41 +00:00
|
|
|
func RenameStack(deployment *apitype.DeploymentV3, newName tokens.StackName, newProject tokens.PackageName) error {
|
|
|
|
contract.Requiref(deployment != nil, "deployment", "must not be nil")
|
2019-08-13 18:21:00 +00:00
|
|
|
|
2019-03-11 19:18:55 +00:00
|
|
|
rewriteUrn := func(u resource.URN) resource.URN {
|
2019-09-26 22:23:09 +00:00
|
|
|
project := u.Project()
|
|
|
|
if newProject != "" {
|
|
|
|
project = newProject
|
|
|
|
}
|
|
|
|
|
2019-03-11 19:18:55 +00:00
|
|
|
// The pulumi:pulumi:Stack resource's name component is of the form `<project>-<stack>` so we want
|
|
|
|
// to rename the name portion as well.
|
2023-12-04 10:36:51 +00:00
|
|
|
if u.QualifiedType() == resource.RootStackType {
|
2023-11-20 08:59:00 +00:00
|
|
|
return resource.NewURN(newName.Q(), project, "", u.QualifiedType(), string(tokens.QName(project)+"-"+newName.Q()))
|
2019-03-11 19:18:55 +00:00
|
|
|
}
|
|
|
|
|
Add tokens.StackName (#14487)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
This adds a new type `tokens.StackName` which is a relatively strongly
typed container for a stack name. The only weakly typed aspect of it is
Go will always allow the "zero" value to be created for a struct, which
for a stack name is the empty string which is invalid. To prevent
introducing unexpected empty strings when working with stack names the
`String()` method will panic for zero initialized stack names.
Apart from the zero value, all other instances of `StackName` are via
`ParseStackName` which returns a descriptive error if the string is not
valid.
This PR only updates "pkg/" to use this type. There are a number of
places in "sdk/" which could do with this type as well, but there's no
harm in doing a staggered roll out, and some parts of "sdk/" are user
facing and will probably have to stay on the current `tokens.Name` and
`tokens.QName` types.
There are two places in the system where we panic on invalid stack
names, both in the http backend. This _should_ be fine as we've had long
standing validation that stacks created in the service are valid stack
names.
Just in case people have managed to introduce invalid stack names, there
is the `PULUMI_DISABLE_VALIDATION` environment variable which will turn
off the validation _and_ panicing for stack names. Users can use that to
temporarily disable the validation and continue working, but it should
only be seen as a temporary measure. If they have invalid names they
should rename them, or if they think they should be valid raise an issue
with us to change the validation code.
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-15 07:44:54 +00:00
|
|
|
return resource.NewURN(tokens.QName(newName.String()), project, "", u.QualifiedType(), u.Name())
|
2019-03-11 19:18:55 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 12:28:41 +00:00
|
|
|
rewriteState := func(res *apitype.ResourceV3) {
|
2023-02-17 18:46:23 +00:00
|
|
|
contract.Assertf(res != nil, "resource state must not be nil")
|
2019-03-11 19:18:55 +00:00
|
|
|
|
|
|
|
res.URN = rewriteUrn(res.URN)
|
|
|
|
|
|
|
|
if res.Parent != "" {
|
|
|
|
res.Parent = rewriteUrn(res.Parent)
|
|
|
|
}
|
|
|
|
|
|
|
|
for depIdx, dep := range res.Dependencies {
|
|
|
|
res.Dependencies[depIdx] = rewriteUrn(dep)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, propDeps := range res.PropertyDependencies {
|
|
|
|
for depIdx, dep := range propDeps {
|
|
|
|
propDeps[depIdx] = rewriteUrn(dep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-16 15:09:32 +00:00
|
|
|
if res.DeletedWith != "" {
|
|
|
|
res.DeletedWith = rewriteUrn(res.DeletedWith)
|
|
|
|
}
|
|
|
|
|
2019-03-11 19:18:55 +00:00
|
|
|
if res.Provider != "" {
|
|
|
|
providerRef, err := providers.ParseReference(res.Provider)
|
|
|
|
contract.AssertNoErrorf(err, "failed to parse provider reference from validated checkpoint")
|
|
|
|
|
|
|
|
providerRef, err = providers.NewReference(rewriteUrn(providerRef.URN()), providerRef.ID())
|
|
|
|
contract.AssertNoErrorf(err, "failed to generate provider reference from valid reference")
|
|
|
|
|
|
|
|
res.Provider = providerRef.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-22 12:28:41 +00:00
|
|
|
for i := range deployment.Resources {
|
|
|
|
rewriteState(&deployment.Resources[i])
|
2019-03-11 19:18:55 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 12:28:41 +00:00
|
|
|
for i := range deployment.PendingOperations {
|
|
|
|
rewriteState(&deployment.PendingOperations[i].Resource)
|
2019-03-11 19:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|