Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11366

Testing the property's value of a list item in an acceptance test

$
0
0

@nboukeffa wrote:

Hi guys,

I would like to know if it’s possible to test the property’s value of a list item in an acceptance test. In the following example I want to verify that the networks list has been correctly modified. Thanks for your help.

	const testAccInstanceConfig = `
	resource "foo" "bar" {
		name = "foobar"
		networks = [
			{code = "123", order = 1}
		]  
	}
`

const testAccCheckInstanceConfigTagsUpdate = `
	resource "foo" "bar" {
		name = "foobar"
		networks = [
			{code = "456", order = 1}
		]
	}
`

resource.Test(t, resource.TestCase{
	Steps: []resource.TestStep{
		{
			Config: testAccInstanceConfig,
			Check: resource.ComposeTestCheckFunc(
				testAccCheckInstanceExists("foo.bar", &v),
				resource.TestCheckResourceAttr("foo.bar", "networks[0].code", "123"),
			),
		},
		{
			Config: testAccCheckInstanceConfigTagsUpdate,
			Check: resource.ComposeTestCheckFunc(
				testAccCheckInstanceExists("foo.bar", &v),
				resource.TestCheckResourceAttr("foo.bar", "networks[0].code", "456"),
			),
		},
	},
})

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 11366

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>