Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Terraform
Commits
8b9fa6d0
Commit
8b9fa6d0
authored
6 years ago
by
James Bardin
Browse files
Options
Download
Email Patches
Plain Diff
add test provider coverage around unknown vals
parent
137974c4
main
0.15.3
26258
Incident16886
MatthewTestBranch
add-cont-valid-callout
add-internals-to-sidebar
add-jsonstate-to-cloudbackendstate
add-jsonstate-to-cloudbackendstate2
add-learn-callout-moved-blocks
add-new-intro-docs
add-note-about-spaces
add-page-metadata
add-tutorial-custom-conditions
add-version-notes-1.2
add-warnings-backends
alisdair/alpine-latest
alisdair/are-consul-tests-running
alisdair/backend-config-override-fix-remote-test
alisdair/concise-diff-experiment
alisdair/disable-preconditions-postconditions
alisdair/duplicate-no-color
alisdair/fix-configload-snapshot-panic
alisdair/fix-remote-backend-migrate-version-check
alisdair/getproviders-retries-bad-branch-do-not-use
alisdair/metadata-functions-command
alisdair/mildwonkey/type-func
alisdair/plan-summary-after-changes
alisdair/prototype-moved-actions
alisdair/providers-list
alisdair/remote-input-variable-unset
alisdair/resource-instance-object-dependencies
alisdair/still-applying-consolidation
alisdair/version-should-include-prerelease
b-1.1-module-source-git
b-check-output-multi-expand
b-check-resource-multi-expand
b-dev-overrides-plan-warning
b-diags-sensitive-value
b-flatten-panic
b-miekg-dns-upgrade
b-module-instance-resource-deps
b-move-implied-cross-package
b-tf-builtin-provider-parser-fix
b-type-conversion-funcs-null
b-yamldecode-emptydoc-null
backport/29156_do_not_log_sensitive_values/nearly-safe-bullfrog
backport/4th-alternate-mirror-directory-fix/closely-key-civet
backport/add-cont-valid-callout/luckily-golden-wildcat
backport/add-format-function-guidance/ultimately-lucky-halibut
backport/add-internals-to-sidebar/willingly-bright-sunbird
backport/add-learn-callout-moved-blocks/multiply-awaited-cub
backport/add-new-intro-docs/strangely-lucky-bluegill
backport/add-powershell-warning/certainly-amazing-lemur
backport/add-version-notes-1.2/amazingly-premium-woodcock
backport/add-warnings-backends/physically-many-mantis
backport/alisdair/cty-1.8.3/seriously-tidy-foal
backport/alisdair/fix-30641/firmly-musical-lemming
backport/alisdair/fix-show-plan-against-non-default-state/blatantly-balanced-porpoise
backport/alisdair/fix-stuck-lock-when-applying-state-plan/enormously-refined-sheepdog
backport/alisdair/json-ui-resource-drift/broadly-careful-rooster
backport/alisdair/pre-convert-optional-defaults/virtually-able-mouse
backport/alisdair/redact-sensitive-values-from-function-errors/definitely-assured-mantis
backport/alisdair/sensitive-attribute-forces-replacement/mildly-optimal-platypus
backport/b-check-resource-multi-expand/extremely-key-sheep
backport/backport/cstella84/patch-add-hyperlink-for-referenced-argument/manually-patient-locust
backport/barrettclark/update-go-slug/severely-destined-crow
backport/bugfix_typos/hardly-sharp-mosquito
backport/clarify-backend-state-storage/ultimately-causal-ladybird
backport/consul-size-limit/amazingly-innocent-python
backport/cstella84/patch-add-hyperlink-for-referenced-argument
backport/description-metadata-language-docs/frankly-desired-penguin
backport/doc-provisioner-scp/definitely-capital-bug
backport/doc-refactoring-nav-link/honestly-sweet-sawfly
backport/doc-s3-fix/utterly-close-rabbit
backport/docs-fix-typo/usefully-blessed-monkey
backport/docs-for-each-list-toset/basically-still-zebra
backport/docs/unknwon-value/completely-musical-lionfish
backport/f-build-go1.19.3/largely-peaceful-grouper
backport/f-cty-funcs-marks/poorly-mutual-walleye
backport/f-non-existing-module-instance-crash/neatly-perfect-kiwi
backport/f-plan-action-reason/incredibly-concrete-jackal
backport/f-plan-refresh-only-and-replace/really-absolute-silkworm
backport/file-provisioner-powershell-warning/noticeably-adequate-mullet
backport/fix-apt-page/abnormally-relative-quagga
backport/fix-backends-link/strangely-emerging-crane
backport/fix-backends-link/vertically-noble-hornet
backport/fix-broken-link/certainly-measured-chipmunk
backport/fix-broken-links-1-10/firmly-equal-rabbit
backport/fix-cdktf-link/highly-pumped-snapper
backport/fix-glossary-table-contents/uniquely-pro-garfish
backport/fix-grammar/precisely-polite-tortoise
backport/fix-internals-overview/globally-allowed-kid
backport/fix-internals-overview/noticeably-up-rodent
backport/fix-intro-page-images/constantly-capable-shiner
backport/fix-last-intro-nits/infinitely-workable-redfish
backport/fix-links-devdot/strictly-notable-sparrow
backport/fix-links-release/seemingly-living-dinosaur
backport/fix-remote-backend-references/primarily-tops-mite
backport/fix-workspace-name-docs/ideally-uncommon-pheasant
backport/jbardin/cancel-auto-approve/extremely-brave-bear
backport/jbardin/coerce-value-nested-types/certainly-rested-chigger
backport/jbardin/format-empty-nested-attrs/rightly-uncommon-bluegill
backport/jbardin/format-id-name-marks/perfectly-boss-bass
backport/jbardin/ignore-changes-marks/formerly-new-insect
backport/jbardin/k8s-mod-update/likely-probable-falcon
backport/jbardin/optional-attrs/obviously-growing-duck
backport/jbardin/static-validate-nested-types/possibly-crack-mouse
backport/k8s-backend-credentials/radically-decent-mite
backport/kevin/rewrite-internal-redirects/quietly-helped-pelican
backport/laura-add-mrui-to-sidebar/highly-resolved-blowfish
backport/main/absolutely-sterling-whippet
backport/main/cleanly-mature-scorpion
backport/mg_no_code_prov_followup/marginally-relevant-eagle
backport/mktg-tf-76ef54dc3c574e032725e0341be8e1d2/constantly-smart-kingfish
backport/mktg-tf-76ef54dc3c574e032725e0341be8e1d2/distinctly-sharp-ferret
backport/mktg-tf-76ef54dc3c574e032725e0341be8e1d2/friendly-evident-grouse
backport/module-invocation-warning/fully-fitting-buzzard
backport/nvanthao/update-docs-implicit-provider/locally-neutral-lemur
backport/optional-type-attributes-note/inherently-dear-goat
backport/patch-1/gladly-mature-oarfish
backport/patch-1/manually-fine-mantis
backport/patch-1/nationally-working-kite
backport/patch-1/noticeably-comic-manatee
backport/patch-1/rarely-informed-gopher
backport/patch-1/sensibly-saving-swine
backport/patch-1/usually-clear-shad
backport/patch-1/vaguely-deciding-beagle
backport/patch-1/virtually-more-rhino
backport/patch-1/wholly-verified-racer
backport/patch-1/willingly-usable-husky
backport/patch-1/yearly-rich-skunk
backport/patch-2/badly-game-spider
backport/patch-2/finally-amazed-catfish
backport/patch-2/openly-clean-tick
backport/patch-2/weekly-selected-tiger
backport/rar-docs-update-add-anchor/cheaply-sincere-escargot
backport/remove-future-statement-import/briefly-viable-glowworm
backport/remove-provisioners/readily-correct-ferret
backport/remove-provisioners/widely-singular-hound
backport/replace-flag-clarifications/definitely-saved-elf
backport/replace-flag-updates/nominally-assured-weevil
backport/startsswith-to-startswith/highly-gorgeous-katydid
backport/system-parameter/infinitely-open-bluebird
backport/tf-integration-program-guide/briefly-certain-quail
backport/tweak-multi-to-multi-migration-tfc/suddenly-real-duckling
backport/update-cloud-block-pages/verbally-key-kangaroo
backport/update-console-docs/closely-genuine-javelin
backport/update-for-each-example/early-crucial-piranha
backport/update-plan-page/lightly-outgoing-halibut
backport/update-run-task-result/factually-star-sunfish
backport/update_docs_for_30072/gradually-trusting-wahoo
backport/workspaces-confusion-fixes/secondly-huge-titmouse
barrettclark/fix-state-outputs-read-permissions
before-sdk-extraction
brandonc/changelog_nested_sensitive
brandonc/changelog_sensitive_diff_fixes
brandonc/cloud_upgrade_013
brandonc/nested_attr_sensitive
brandonc/output_cloud_reads
brandonc/providers-estimate
brandonc/run_variables_types
brandonc/scheme_override_cloud
brandonc/variable_parsing_refactor
build-circleci
build-pr-checks
build-workflow-dev/cgo-enabled
build-workflow-dev/liamcervante/equivalence-test-action
bump-gcp-storage-dependency
bump-gcp-storage-dependency-2
cgriggs01-stable-pdp
cgriggs01-tpdp-default
cloud-e2e-fix
cloud-integration-changelog-entry
cmd-fmt-parens-error
dependabot/go_modules/github.com/bmatcuk/doublestar-1.3.4
dependabot/go_modules/github.com/mattn/go-shellwords-1.0.12
dev-portal-updates-docs
dividers-devdot-fixes
doc-config-refactoring
doc-provisioner-scp
doc-refactoring-nav-link
doc-s3-backend-dynamodb-locks
doc-unicode-hcl
doc-yamlencode-stable
docs-for-each-list-toset
docs-readme-updates-versioned-docs
docs/top-pages-gloss
ds.submodule-nav-main
f-addrs-static-checkable
f-build-go1.19.3
f-cli-hide-fast-refresh
f-cliconfig-hcl2api
f-cmd-output-raw
f-cmd-show-config
f-cmd-web
f-cmdline-funcs
f-config-refcount
f-core-rpc
f-cty-funcs-marks
f-debugger
f-decode-moved
f-depfile-pkg
f-derived-values-tracking
f-diagnostics-cli-reorg
f-dynamic-provider-assignment
f-e2etest-deps-forbidden
f-expand-root-outputs
f-exprstress
f-fewer-apply-updates
f-fileexists-errmsg
f-func-cidrsubnets
f-func-expandnull
f-functions-in-providers
f-gen-integration-tests
f-implied-move-module-call
f-init-provider-source-feedback
f-jsonstate-2
f-langserver
f-moduletest-2
f-moved-again
f-new-build-pipeline
f-new-plan-modes
f-ng-workflow
f-nix-legacy-providers
f-output-value-types
f-outputs-plan
f-partial-plan-on-error
f-partial-plan-on-error-ui
f-persistent-checks-old
f-plan-immediate-ops
f-plan-reads
f-plan-refresh-only-and-replace
f-playground
f-plugin-finder
f-possible-apply-refactoring
f-preconditions-postconditions
f-prototype-drift
f-prototype-workspaces-are-states
f-provider-http-mirrors
f-provider-source-local-discovery
f-provider-state-storage
f-providerinst-command-tests
f-providers-mirror
f-providers-mirror-2
f-providers-new-installer
f-refresh-plan
f-resource-for_each-and-experiments
f-rpcplugin-interface
f-skip-attrs-as-blocks
f-state-upgrade-always
f-submodule-outputs-inferred-sensitive
f-svcauth-environment
f-temp-without-provider-blocks
f-template-values
f-terraform-version-lock
f-testing-eval-prototype
f-testing-with-conditions
f-tfaddr-lib
f-unused-attr
f-validate-lint
f-workspaces2-prototype
f/azurerm-backend-msal
fix-apt-page
fix-broken-link
fix-broken-links-1-10
fix-cdktf-link
fix-dividers-for-devdot
fix-future-facing-language
fix-future-lang-2
fix-internals-overview
fix-intro-page-images
fix-last-intro-nits
fix-links-devdot
fix-links-release
fix-postconditions-example
fix-preconditions
fix-provisioners-content
fix-readme-again
fix-value-assertion-errors
gcs-backend-add-kms
gcs-backend-add-private-connect-support
gcs-refactor-credential-handling
gitrgoliveira-patch-1
go-get1.5.2
gs/add-pre-plan-run-tasks
jan21_language_urls
jan21_test_broken_link_check
jan21_url_rfc
jbardin/1.3-destroy-perf
jbardin/backport-29017
jbardin/backport-29167
jbardin/backport-29559
jbardin/backport-31576
jbardin/call-plan-destroy
jbardin/data-source-destroy-edges
jbardin/go-getter-update
jbardin/lookup-objects
jbardin/null-variable
jbardin/output-perf
jbardin/plan-orphan-deleted
jbardin/remove-deprecated-backends
jbardin/resolved-provided-by
jbardin/terraform-data
jbardin/terraform-null
jbardin/trigger-replacement
jbardin/variable-eval
json-schema-export-crash
july2020_pre0.13_stable-website_backup
k8s-backend-credentials
k8sback
kevin/local-preview-post-split
kevin/preview
kevin/remove-guides-docs
kevin/vercel-config
kmoe/http-backend-debug-log
kmoe/init-checksum-miss-error
kmoe/misc-help-text
kmoe/unused-resource-attributes
lafentres/autolabel-dependabot-prs
lafentres/refactor-show-command
laura-fix-jsonencode-note
laura-update-docs-readme
laura-update-pre-post-conditions
liamcervante/cicd-go-vet
liamcervante/structured-run-output
link_multicloud_tutorial_from_use_cases
link_to_refresh_tutorial
link_workflow_tutorials
megan_invalid_creds
megan_update_msg
migrate-go-tfe-1_0
mnomitch/varialbe-errors-on-remote-backend
nf/nov21-migrate-away-from-cloud
nq.content-update
nq.docs-content-update
omarismail/run-vars
p-go-azure-helpers-0.10.0
paddy_backport_proto6_download
paddy_module_attribution_tmp
paddy_paul_proto52
paddy_protocol_six_registry
paddy_tf_log_json
pault/0.14-tfce-continue-on-error
pluginsdk-v0.12-early6
pluginsdk-v0.12-early7
pluginsdk-v0.12-early8
preapply-runtasks-cli-output
preapply-runtasks-clioutput
prototype-implicit-graph
ps-protocol2
pselle/env_delete
rar-docs-update-add-anchor
regenerate-protobufs
registry-provider-tiers
release-notes-env-credentials
remote-backend-refresh-alias
replace-flag-updates
res-add-learn-link-debug
res-add-learn-link-debug-1
res-lifecycle-tutorial
revamp-cli-config
revert-29088-minify_jsonencode
review-1.0-docs
rln-add-versions-tutorials-links
rln-modules-track-reference
rt-backport-changelog
rt-changelog-entry-1.1
run-tasks-backport
sdk-removed
sebasslash/add-cloud-e2e-test-workflow
sebasslash/add-tf-hostname-env-var
sebasslash/add-tf-org-env-var
sebasslash/env-cloud-e2e-tests
sebasslash/err-approval-input-false
sebasslash/resolve-flaky-env-var-test
sebasslash/tf-workspace-cloud-config
solutiongeek-patch-1
stable-website
tags-reconfigure-msg
tchupp/override-local-vars
test-branch-protection-workflow
tf-swift-backend-swauth
tfc-integration-docs
uk1288/backport-cloud-integration-panic-fix
uk1288/fix-for-cloud-integration-panic
uk1288/update-changelog-md
uk1288/update-changelog-md-v1-1
update-TF-WORKSPACE-variable
update-cidrnetmask-docs
update-depends-on-docs
update-for-each-example
update-packaging-action-name
update-tfe-login-flow
update_gen_meta
uturunku1-patch-1
uturunku1-patch-2
v0.12
v0.13
v0.14
v0.15
v1.0
v1.1
v1.4.0-alpha20221109
v1.3.5
v1.3.4
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc1
v1.3.0-dev
v1.3.0-beta1
v1.3.0-alpha20220817
v1.3.0-alpha20220803
v1.3.0-alpha20220706
v1.3.0-alpha20220622
v1.3.0-alpha20220608
v1.2.9
v1.2.8
v1.2.7
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc2
v1.2.0-rc1
v1.2.0-beta1
v1.2.0-alpha20220413
v1.2.0-alpha-20220328
v1.1.9
v1.1.8
v1.1.7
v1.1.6
v1.1.5
v1.1.4
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.1.0-rc1
v1.1.0-beta2
v1.1.0-beta1
v1.1.0-alpha20211029
v1.1.0-alpha20211020
v1.1.0-alpha20211006
v1.1.0-alpha20210922
v1.1.0-alpha20210908
v1.1.0-alpha20210811
v1.1.0-alpha20210728
v1.1.0-alpha20210714
v1.1.0-alpha20210630
v1.1.0-alpha20210616
v1.0.11
v1.0.10
v1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
v0.15.5
v0.15.4
v0.15.3
v0.15.2
v0.15.1
v0.15.0
v0.15.0-rc2
v0.15.0-rc1
v0.15.0-beta2
v0.15.0-beta1
v0.15.0-alpha20210210
v0.15.0-alpha20210127
v0.15.0-alpha20210107
v0.14.11
v0.14.10
v0.14.9
v0.14.8
v0.14.7
v0.14.6
v0.14.5
v0.14.4
v0.14.3
v0.14.2
v0.14.1
v0.14.0
v0.14.0-rc1
v0.14.0-beta2
v0.14.0-beta1
v0.14.0-alpha20201007
v0.14.0-alpha20200923
v0.14.0-alpha20200910
v0.13.7
v0.13.6
v0.13.5
v0.13.4
v0.13.3
v0.13.2
v0.13.1
v0.13.0
v0.13.0-rc1
v0.13.0-beta3
v0.13.0-beta2
v0.13.0-beta1
v0.12.31
v0.12.30
v0.12.29
v0.12.28
v0.12.27
v0.12.26
v0.12.25
v0.12.24
v0.12.23
v0.12.22
v0.12.21
v0.12.20
v0.12.19
v0.12.18
v0.12.17
v0.12.16
v0.12.15
v0.12.14
v0.12.13
v0.12.12
v0.12.11
v0.12.10
v0.12.9
v0.12.8
v0.12.7
v0.12.6
v0.12.5
v0.12.4
v0.12.3
v0.12.2
v0.12.1
v0.12.0
v0.12.0-rc1
v0.12.0-dev20190520H16
v0.12.0-beta2
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
builtin/providers/test/resource.go
+14
-0
builtin/providers/test/resource.go
builtin/providers/test/resource_list.go
+20
-0
builtin/providers/test/resource_list.go
builtin/providers/test/resource_list_test.go
+129
-0
builtin/providers/test/resource_list_test.go
builtin/providers/test/resource_test.go
+126
-0
builtin/providers/test/resource_test.go
with
289 additions
and
0 deletions
+289
-0
builtin/providers/test/resource.go
+
14
-
0
View file @
8b9fa6d0
...
...
@@ -18,6 +18,13 @@ func testResource() *schema.Resource {
State
:
schema
.
ImportStatePassthrough
,
},
CustomizeDiff
:
func
(
d
*
schema
.
ResourceDiff
,
_
interface
{})
error
{
if
d
.
HasChange
(
"required"
)
{
d
.
SetNewComputed
(
"planned_computed"
)
}
return
nil
},
Schema
:
map
[
string
]
*
schema
.
Schema
{
"required"
:
{
Type
:
schema
.
TypeString
,
...
...
@@ -129,6 +136,11 @@ func testResource() *schema.Resource {
Optional
:
true
,
Description
:
"return and error during apply"
,
},
"planned_computed"
:
{
Type
:
schema
.
TypeString
,
Computed
:
true
,
Description
:
"copied the required field during apply, and plans computed when changed"
,
},
},
}
}
...
...
@@ -164,6 +176,8 @@ func testResourceRead(d *schema.ResourceData, meta interface{}) error {
d
.
Set
(
"computed_list"
,
[]
string
{
"listval1"
,
"listval2"
})
d
.
Set
(
"computed_set"
,
[]
string
{
"setval1"
,
"setval2"
})
d
.
Set
(
"planned_computed"
,
d
.
Get
(
"required"
))
// if there is no "set" value, erroneously set it to an empty set. This
// might change a null value to an empty set, but we should be able to
// ignore that.
...
...
This diff is collapsed.
Click to expand it.
builtin/providers/test/resource_list.go
+
20
-
0
View file @
8b9fa6d0
...
...
@@ -11,6 +11,13 @@ func testResourceList() *schema.Resource {
Update
:
testResourceListUpdate
,
Delete
:
testResourceListDelete
,
CustomizeDiff
:
func
(
d
*
schema
.
ResourceDiff
,
_
interface
{})
error
{
if
d
.
HasChange
(
"dependent_list"
)
{
d
.
SetNewComputed
(
"computed_list"
)
}
return
nil
},
Schema
:
map
[
string
]
*
schema
.
Schema
{
"list_block"
:
{
Type
:
schema
.
TypeList
,
...
...
@@ -55,6 +62,19 @@ func testResourceList() *schema.Resource {
},
},
},
"sublist_block_optional"
:
{
Type
:
schema
.
TypeList
,
Optional
:
true
,
Elem
:
&
schema
.
Resource
{
Schema
:
map
[
string
]
*
schema
.
Schema
{
"list"
:
{
Type
:
schema
.
TypeList
,
Optional
:
true
,
Elem
:
&
schema
.
Schema
{
Type
:
schema
.
TypeString
},
},
},
},
},
},
},
},
...
...
This diff is collapsed.
Click to expand it.
builtin/providers/test/resource_list_test.go
+
129
-
0
View file @
8b9fa6d0
...
...
@@ -318,3 +318,132 @@ resource "test_resource_list" "foo" {
},
})
}
func
TestResourceList_planUnknownInterpolation
(
t
*
testing
.
T
)
{
resource
.
UnitTest
(
t
,
resource
.
TestCase
{
Providers
:
testAccProviders
,
CheckDestroy
:
testAccCheckResourceDestroy
,
Steps
:
[]
resource
.
TestStep
{
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource_list" "foo" {
list_block {
string = "x"
}
}
resource "test_resource_list" "bar" {
list_block {
sublist = [
test_resource_list.foo.list_block[0].string,
]
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource_list.bar"
,
"list_block.0.sublist.0"
,
"x"
,
),
),
},
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource_list" "foo" {
list_block {
string = "x"
}
dependent_list {
val = "y"
}
}
resource "test_resource_list" "bar" {
list_block {
sublist = [
test_resource_list.foo.computed_list[0],
]
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource_list.bar"
,
"list_block.0.sublist.0"
,
"y"
,
),
),
},
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource_list" "foo" {
list_block {
string = "x"
}
dependent_list {
val = "z"
}
}
resource "test_resource_list" "bar" {
list_block {
sublist = [
test_resource_list.foo.computed_list[0],
]
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource_list.bar"
,
"list_block.0.sublist.0"
,
"z"
,
),
),
},
},
})
}
func
TestResourceList_planUnknownInterpolationList
(
t
*
testing
.
T
)
{
resource
.
UnitTest
(
t
,
resource
.
TestCase
{
Providers
:
testAccProviders
,
CheckDestroy
:
testAccCheckResourceDestroy
,
Steps
:
[]
resource
.
TestStep
{
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource_list" "foo" {
dependent_list {
val = "y"
}
}
resource "test_resource_list" "bar" {
list_block {
sublist_block_optional {
list = test_resource_list.foo.computed_list
}
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource_list.bar"
,
"list_block.0.sublist_block_optional.0.list.0"
,
"y"
,
),
),
},
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource_list" "foo" {
dependent_list {
val = "z"
}
}
resource "test_resource_list" "bar" {
list_block {
sublist_block_optional {
list = test_resource_list.foo.computed_list
}
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource_list.bar"
,
"list_block.0.sublist_block_optional.0.list.0"
,
"z"
,
),
),
},
},
})
}
This diff is collapsed.
Click to expand it.
builtin/providers/test/resource_test.go
+
126
-
0
View file @
8b9fa6d0
...
...
@@ -790,3 +790,129 @@ resource "test_resource" "foo" {
},
})
}
func
TestResource_optionalComputedMap
(
t
*
testing
.
T
)
{
resource
.
UnitTest
(
t
,
resource
.
TestCase
{
Providers
:
testAccProviders
,
CheckDestroy
:
testAccCheckResourceDestroy
,
Steps
:
[]
resource
.
TestStep
{
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource" "foo" {
required = "yep"
required_map = {
key = "value"
}
optional_computed_map = {
foo = "bar"
baz = ""
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource.foo"
,
"optional_computed_map.foo"
,
"bar"
,
),
resource
.
TestCheckResourceAttr
(
"test_resource.foo"
,
"optional_computed_map.baz"
,
""
,
),
),
},
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource" "foo" {
required = "yep"
required_map = {
key = "value"
}
optional_computed_map = {}
}
`
),
// removing the map from the config should still leave an empty computed map
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource.foo"
,
"optional_computed_map.%"
,
"0"
,
),
),
},
},
})
}
func
TestResource_plannedComputed
(
t
*
testing
.
T
)
{
resource
.
UnitTest
(
t
,
resource
.
TestCase
{
Providers
:
testAccProviders
,
CheckDestroy
:
testAccCheckResourceDestroy
,
Steps
:
[]
resource
.
TestStep
{
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource" "foo" {
required = "ok"
required_map = {
key = "value"
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource.foo"
,
"planned_computed"
,
"ok"
,
),
),
},
resource
.
TestStep
{
Config
:
strings
.
TrimSpace
(
`
resource "test_resource" "foo" {
required = "changed"
required_map = {
key = "value"
}
}
`
),
Check
:
resource
.
ComposeTestCheckFunc
(
resource
.
TestCheckResourceAttr
(
"test_resource.foo"
,
"planned_computed"
,
"changed"
,
),
),
},
},
})
}
func
TestDiffApply_map
(
t
*
testing
.
T
)
{
resSchema
:=
map
[
string
]
*
schema
.
Schema
{
"map"
:
{
Type
:
schema
.
TypeMap
,
Optional
:
true
,
Computed
:
true
,
Elem
:
&
schema
.
Schema
{
Type
:
schema
.
TypeString
},
},
}
priorAttrs
:=
map
[
string
]
string
{
"id"
:
"ok"
,
"map.%"
:
"2"
,
"map.foo"
:
"bar"
,
"map.bar"
:
""
,
}
diff
:=
&
terraform
.
InstanceDiff
{
Attributes
:
map
[
string
]
*
terraform
.
ResourceAttrDiff
{
"map.foo"
:
&
terraform
.
ResourceAttrDiff
{
Old
:
"bar"
,
New
:
""
,
NewRemoved
:
true
},
"map.bar"
:
&
terraform
.
ResourceAttrDiff
{
Old
:
""
,
New
:
""
,
NewRemoved
:
true
},
},
}
newAttrs
,
err
:=
diff
.
Apply
(
priorAttrs
,
(
&
schema
.
Resource
{
Schema
:
resSchema
})
.
CoreConfigSchema
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expect
:=
map
[
string
]
string
{
"id"
:
"ok"
,
"map.%"
:
"0"
,
}
if
!
reflect
.
DeepEqual
(
newAttrs
,
expect
)
{
t
.
Fatalf
(
"expected:%#v got:%#v"
,
expect
,
newAttrs
)
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help