Skip to content

Commit 0a1a309

Browse files
authored
Show a warning message if a resource is not in GroupToTerraformName (#3463)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> When introducing a new resource to the system it does not get a mention in the plan automatically. Instead, developer must know that the new resource has to be added to the GroupToTerraformName map for it. The warning message is a good indicator for the developer of the new resource that an extra step is needed for the resource support. I opted for the warning message instead of panicking because apparently there are resources that do not need to be in the plan, but there is no comprehensive list of such resources provided and I am not sure that the test suite covers every such resource, it is not a great experience for the bundle operation to be blocked just because the resource is in neither of the lists. ## Tests <!-- How have you tested the changes? --> Existing tests are green <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 15ae8ef commit 0a1a309

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

bundle/deploy/terraform/showplanfile.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ import (
44
"context"
55

66
"github.com/databricks/cli/bundle/deployplan"
7+
"github.com/databricks/cli/libs/log"
78
"github.com/hashicorp/terraform-exec/tfexec"
89
tfjson "github.com/hashicorp/terraform-json"
910
)
1011

12+
// silentlyUpdatedResources contains resource types that are automatically created by DABs,
13+
// no need to show them in the plan
14+
var silentlyUpdatedResources = map[string]bool{
15+
"databricks_grants": true,
16+
"databricks_permissions": true,
17+
"databricks_secret_acl": true,
18+
}
19+
1120
// GetActions converts Terraform resource changes into deployplan.Action values.
1221
// The returned slice can be filtered using deployplan.Filter and FilterGroup helpers.
13-
func GetActions(changes []*tfjson.ResourceChange) []deployplan.Action {
22+
func GetActions(ctx context.Context, changes []*tfjson.ResourceChange) []deployplan.Action {
1423
var result []deployplan.Action
1524

1625
for _, rc := range changes {
@@ -34,8 +43,9 @@ func GetActions(changes []*tfjson.ResourceChange) []deployplan.Action {
3443

3544
group, ok := TerraformToGroupName[rc.Type]
3645
if !ok {
37-
// Happens for databricks_grant, databricks_permissions, databricks_secrets_acl.
38-
// These are automatically created by DABs, no need to show them.
46+
if !silentlyUpdatedResources[rc.Type] {
47+
log.Warnf(ctx, "unknown resource type '%s'", rc.Type)
48+
}
3949
continue
4050
}
4151

@@ -59,5 +69,5 @@ func ShowPlanFile(ctx context.Context, tf *tfexec.Terraform, planPath string) ([
5969
return nil, err
6070
}
6171

62-
return GetActions(plan.ResourceChanges), nil
72+
return GetActions(ctx, plan.ResourceChanges), nil
6373
}

bundle/phases/deploy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestParseTerraformActions(t *testing.T) {
4141
},
4242
}
4343

44-
actions := terraform.GetActions(changes)
44+
actions := terraform.GetActions(t.Context(), changes)
4545
res := deployplan.FilterGroup(actions, "pipelines", deployplan.ActionTypeDelete, deployplan.ActionTypeRecreate)
4646

4747
assert.Equal(t, []deployplan.Action{

0 commit comments

Comments
 (0)