-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix inconsistent results after apply (#146)
After the change where we allow customers to configure the `space` at the provider level, I found two issues when running Terraform apply: Error 1: Error: Provider returned invalid result object after apply After the apply operation, the provider still indicated an unknown value for mondoo_integration_slack.space.space_id. All values must be known after apply, so this is always a bug in the provider and should be reported in the provider's own repository. Terraform will still save the other known object values in the state. Error 2: Error: Provider produced inconsistent result after apply When applying changes to mondoo_integration_slack.space, provider "provider[\"registry.terraform.io/hashicorp/mondoo\"]" produced an unexpected new value: .space_id: was null, but now cty.StringVal("silly-hamilton-515695"). This is a bug in the provider, which should be reported in the provider's own issue tracker. This change fixes both of these issues. Note that we didn't catch this issue for the lack of acceptance tests on all integration resources, I added tests for two integrations, Slack and Shodan, but we probably need to do the rest of them soon. Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
19 changed files
with
305 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccShodanResource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Create and Read testing | ||
{ | ||
Config: testAccShodanResourceConfig(accSpace.ID(), "one", []string{"mondoo.com"}), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "name", "one"), | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
{ | ||
Config: testAccShodanResourceWithSpaceInProviderConfig(accSpace.ID(), "two", "abctoken12345"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "name", "two"), | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
// ImportState testing | ||
// @afiune this doesn't work since most of our resources doesn't have the `id` attribute | ||
// if we add it, instead of the `mrn` or as a copy, this import test will work | ||
// { | ||
// ResourceName: "mondoo_integration_shodan.test", | ||
// ImportState: true, | ||
// ImportStateVerify: true, | ||
// }, | ||
// Update and Read testing | ||
{ | ||
Config: testAccShodanResourceConfig(accSpace.ID(), "three", []string{"mondoo.com"}), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "name", "three"), | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
{ | ||
Config: testAccShodanResourceWithSpaceInProviderConfig(accSpace.ID(), "four", "0987xyzabc7654"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "name", "four"), | ||
resource.TestCheckResourceAttr("mondoo_integration_shodan.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
// Delete testing automatically occurs in TestCase | ||
}, | ||
}) | ||
} | ||
|
||
func testAccShodanResourceConfig(spaceID, intName string, targets []string) string { | ||
return fmt.Sprintf(` | ||
resource "mondoo_integration_shodan" "test" { | ||
space_id = %[1]q | ||
name = %[2]q | ||
targets = %[3]q | ||
credentials = { | ||
token = "abcd1234567890" | ||
} | ||
} | ||
`, spaceID, intName, targets) | ||
} | ||
|
||
func testAccShodanResourceWithSpaceInProviderConfig(spaceID, intName, token string) string { | ||
return fmt.Sprintf(` | ||
provider "mondoo" { | ||
space = %[1]q | ||
} | ||
resource "mondoo_integration_shodan" "test" { | ||
name = %[2]q | ||
targets = ["8.8.8.8"] | ||
credentials = { | ||
token = %[3]q | ||
} | ||
} | ||
`, spaceID, intName, token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccSlackResource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Create and Read testing | ||
{ | ||
Config: testAccSlackResourceConfig(accSpace.ID(), "one"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "name", "one"), | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
{ | ||
Config: testAccSlackResourceWithSpaceInProviderConfig(accSpace.ID(), "two"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "name", "two"), | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
// ImportState testing | ||
// @afiune this doesn't work since most of our resources doesn't have the `id` attribute | ||
// if we add it, instead of the `mrn` or as a copy, this import test will work | ||
// { | ||
// ResourceName: "mondoo_integration_slack.test", | ||
// ImportState: true, | ||
// ImportStateVerify: true, | ||
// }, | ||
// Update and Read testing | ||
{ | ||
Config: testAccSlackResourceConfig(accSpace.ID(), "three"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "name", "three"), | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
{ | ||
Config: testAccSlackResourceWithSpaceInProviderConfig(accSpace.ID(), "four"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "name", "four"), | ||
resource.TestCheckResourceAttr("mondoo_integration_slack.test", "space_id", accSpace.ID()), | ||
), | ||
}, | ||
// Delete testing automatically occurs in TestCase | ||
}, | ||
}) | ||
} | ||
|
||
func testAccSlackResourceConfig(spaceID, intName string) string { | ||
return fmt.Sprintf(` | ||
resource "mondoo_integration_slack" "test" { | ||
space_id = %[1]q | ||
name = %[2]q | ||
slack_token = "xoxa-1234567890abc" | ||
} | ||
`, spaceID, intName) | ||
} | ||
|
||
func testAccSlackResourceWithSpaceInProviderConfig(spaceID, intName string) string { | ||
return fmt.Sprintf(` | ||
provider "mondoo" { | ||
space = %[1]q | ||
} | ||
resource "mondoo_integration_slack" "test" { | ||
name = %[2]q | ||
slack_token = "xoxa-1234567890abc" | ||
} | ||
`, spaceID, intName) | ||
} |
Oops, something went wrong.