Skip to content

Commit 89a655d

Browse files
committed
special case for custom resources
1 parent 1f818b4 commit 89a655d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

provider/pkg/provider/provider.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,11 @@ func (k *azureNativeProvider) applyDefaults(ctx context.Context, urn string, ran
638638
}
639639

640640
// Apply the apiVersion of this resource.
641+
// Note that some resource types do not have an apiVersion property (e.g. storage:Blob).
641642
if version.GetVersion().Major >= 3 {
642-
news["apiVersion"] = resource.NewStringProperty(res.APIVersion)
643+
if res.APIVersion != "" {
644+
news["apiVersion"] = resource.NewStringProperty(res.APIVersion)
645+
}
643646
}
644647
}
645648

@@ -846,14 +849,14 @@ func (k *azureNativeProvider) Diff(_ context.Context, req *rpc.DiffRequest) (*rp
846849
logging.V(9).Infof("no __inputs found for '%s'", urn)
847850
}
848851

849-
852+
// v2-to-v3 migration: apiVersion might be available in the old state and we use it to suppress spurious diffs.
850853
migratedApiVersion := false
851854
if version.GetVersion().Major >= 3 {
852855
if _, ok := oldInputs["apiVersion"]; !ok {
853-
// migration case: apiVersion might be available in the old state
854-
// and we use it to suppress spurious diffs
855-
oldInputs["apiVersion"] = oldState["apiVersion"]
856-
migratedApiVersion = true
856+
if v, ok := oldState["apiVersion"]; ok {
857+
oldInputs["apiVersion"] = v
858+
migratedApiVersion = true
859+
}
857860
}
858861
}
859862

@@ -888,9 +891,9 @@ func (k *azureNativeProvider) Diff(_ context.Context, req *rpc.DiffRequest) (*rp
888891
// Based on the detailed diff above, calculate the list of changes and replacements.
889892
changes, replaces := calculateChangesAndReplacements(detailedDiff, oldInputs, newResInputs, oldState, *res)
890893

891-
if version.GetVersion().Major >= 3 && migratedApiVersion {
894+
if migratedApiVersion {
892895
if v, ok := detailedDiff["apiVersion"]; ok {
893-
// in this case, the diff is between the old state and the new inputs
896+
// in this case, the diff is between the old state and the new inputs.
894897
v.InputDiff = false
895898
}
896899
}
@@ -1648,8 +1651,10 @@ func checkpointObject(res *resources.AzureAPIResource, inputs resource.PropertyM
16481651
object["__inputs"] = resource.MakeSecret(resource.NewObjectProperty(inputs))
16491652
}
16501653

1651-
// emit the actual apiversion as an output property
1652-
object["apiVersion"] = resource.NewStringProperty(res.APIVersion)
1654+
// emit the actual apiversion as an output property, for resources that have an apiVersion property.
1655+
if res.APIVersion != "" {
1656+
object["apiVersion"] = resource.NewStringProperty(res.APIVersion)
1657+
}
16531658
return object
16541659
}
16551660

0 commit comments

Comments
 (0)