Skip to content

Commit

Permalink
fix: Include backend in dependent bodies to avoid false negatives
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Sep 4, 2023
1 parent 5a6413c commit 0a39159
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 66 deletions.
5 changes: 5 additions & 0 deletions schema/schema_merge_remote_state_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func (sm *SchemaMerger) dependentBodyForRemoteStateDataSource(providerAddr lang.

dsSchema := &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"backend": {
Constraint: backends.BackendTypesAsOneOfConstraint(sm.terraformVersion),
IsRequired: true,
SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent},
},
"config": {
Constraint: objConstraint,
IsOptional: true,
Expand Down
150 changes: 120 additions & 30 deletions schema/schema_merge_v012_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,94 +1339,184 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"artifactory"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["artifactory"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["artifactory"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"artifactory"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["artifactory"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["artifactory"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"atlas"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["atlas"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["atlas"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"atlas"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["atlas"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["atlas"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"azure"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azure"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azure"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"azure"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azure"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azure"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"azurerm"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azurerm"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azurerm"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"azurerm"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azurerm"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["azurerm"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"consul"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["consul"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["consul"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"consul"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["consul"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["consul"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"etcd"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcd"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcd"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"etcd"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcd"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcd"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"etcdv3"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcdv3"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcdv3"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"etcdv3"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcdv3"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["etcdv3"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"gcs"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["gcs"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["gcs"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"gcs"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["gcs"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["gcs"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"http"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["http"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["http"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"http"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["http"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["http"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"local"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["local"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["local"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"local"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["local"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["local"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"manta"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["manta"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["manta"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"manta"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["manta"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["manta"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"pg"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["pg"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["pg"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"pg"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["pg"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["pg"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"remote"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["remote"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["remote"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"remote"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["remote"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["remote"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"s3"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["s3"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["s3"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"s3"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["s3"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["s3"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"swift"}},{"name":"provider","expr":{"addr":"terraform"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["swift"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["swift"]},
},
},
`{"labels":[{"index":0,"value":"terraform_remote_state"}],"attrs":[{"name":"backend","expr":{"static":"swift"}}]}`: {
Attributes: map[string]*schema.AttributeSchema{"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["swift"]}},
Attributes: map[string]*schema.AttributeSchema{
"backend": {IsRequired: true, Constraint: backends.BackendTypesAsOneOfConstraint(v0_12_0), SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent}},
"config": {IsOptional: true, Constraint: backends.ConfigsAsObjectConstraint(v0_12_0)["swift"]},
},
},
},
},
Expand Down
Loading

0 comments on commit 0a39159

Please sign in to comment.