From 8c31439253d25aafb54fc09d89e547fa8238258c Mon Sep 17 00:00:00 2001 From: Scott Winkler Date: Thu, 26 Jan 2023 17:00:20 -0800 Subject: [PATCH] fix: saml integration test (#1494) * fix test * fix: ignore parameter that cannot be read * fix: ignore parameter that cannot be read * update readme --- README.md | 82 +++++++++---------- .../saml_integration_acceptance_test.go | 8 +- pkg/resources/warehouse_acceptance_test.go | 2 +- 3 files changed, 42 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 118274bd7b..996bfa5093 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is a terraform provider plugin for managing [Snowflake](https://www.snowfla ## Getting Help -If you need help, try the [discussions area](https://github.com/Snowflake-Labs/terraform-provider-snowflake/discussions) of this repo. +If you need help, try the [discussions area](https://github.com/Snowflake-Labs/terraform-provider-snowflake/discussions) of this repo. We also use this forum to discuss new features and changes to the provider. **Note**: If you are an enterprise customer, please file a support ticket with your Snowflake account representative. We prioritize support tickets over GitHub issues. Also it helps us with allocating additional engineering resources to supporting the provider. @@ -23,7 +23,7 @@ terraform { required_providers { snowflake = { source = "Snowflake-Labs/snowflake" - version = "~> 0.55.0" + version = "~> 0.56.0" } } } @@ -82,39 +82,30 @@ In-depth docs are available [on the Terraform registry](https://registry.terrafo If you do not have Go installed: 1. Install Go `brew install golang` -2. Make a Go development directory wherever you like `mkdir go_projects` -3. Add the following config to your profile +2. Ensure that your GOPATH is set correctly +3. Fork this repo and clone it into `~/go/src/github.com/Snowflake-Labs/terraform-provider-snowflake` +4. cd to `terraform-provider-snowflake` and install all the required packages with `go get` +5. Build provider with `go install` - ```shell - export GOPATH=$HOME/../go_projects # edit with your go_projects dir - export PATH=$PATH:$GOPATH/bin - ``` - -4. Fork this repo and clone it into `go_projects` -5. cd to `terraform-provider-snowflake` and install all the required packages with `make setup` -6. Finally install goimports with `(cd && go install golang.org/x/tools/cmd/goimports@latest)`. -7. You should now be able to successfully run the tests with `make test` - -It has not been tested on Windows, so if you find problems let us know. - -If you want to build and test the provider locally there is a make target `make install-tf` that will build the provider binary and install it in a location that terraform can find. - -To debug the provider with a debugger: -1. Launch the provider with the `-debug` command line argument in your debugger session. Once the provider starts, it will print instructions on setting the `TF_REATTACH_PROVIDERS` environment variable. - ``` - Provider started. To attach Terraform CLI, set the TF_REATTACH_PROVIDERS environment variable with the following: - - Command Prompt: set "TF_REATTACH_PROVIDERS={"registry.terraform.io/Snowflake-Labs/snowflake":{"Protocol":"grpc","ProtocolVersion":5,"Pid":35140,"Test":true,"Addr": {"Network":"tcp","String":"127.0.0.1:54706"}}}" - PowerShell: $env:TF_REATTACH_PROVIDERS='{"registry.terraform.io/Snowflake-Labs/snowflake":{"Protocol":"grpc","ProtocolVersion":5,"Pid":35140,"Test":true,"Addr":{"Network":"tcp","String":"127.0.0.1:54706"}}}' - ``` -2. Open a terminal where you will execute Terraform and set the `TF_REATTACH_PROVIDERS` environment variable using the command from the first step. -3. Run Terraform as usual from this terminal. Any breakpoints you set will halt execution and you can troubleshoot the provider from your debugger. - -**Note**: The `TF_REATTACH_PROVIDERS` environment variable needs to be set every time you restart your debugger session as some values like the `Pid` or the TCP port will change with every execution. +## Testing +The following environment variables need to be set for acceptance tests to run: +* `SNOWFLAKE_ACCOUNT` - The account name +* `SNOWFLAKE_USER` - A snowflake user for running tests. +* `SNOWFLAKE_PASSWORD` - Password for that user. +* `SNOWFLAKE_ROLE` - Needs to be ACCOUNTADMIN or similar. +* `SNOWFLAKE_REGION` - Default is us-west-2, set this if your snowflake account is in a different region. +* `TEST_ACC` - to enable acc tests. -For further instructions, please check the official [Terraform Plugin Development guide](https://www.terraform.io/plugin/debugging#starting-a-provider-in-debug-mode). +e.g. -## Testing +``` +export SNOWFLAKE_ACCOUNT=TESTACCOUNT +export SNOWFLAKE_USER=TEST_USER +export SNOWFLAKE_PASSWORD=hunter2 +export SNOWFLAKE_ROLE=ACCOUNTADMIN +export SNOWFLAKE_REGION=us-west-2 +export TEST_ACC=true +``` **Note: PRs for new resources will not be accepted without passing acceptance tests.** @@ -130,27 +121,28 @@ The 'acceptance' tests run the full stack, creating, modifying and destroying re To run all tests, including the acceptance tests, run `make test-acceptance`. -### Pull Request CI - -Our CI jobs run the full acceptance test suite, which involves creating and destroying resources in a live snowflake account. Github Actions is configured with environment variables to authenticate to our test snowflake account. For security reasons, those variables are not available to forks of this repo. If you are making a PR from a forked repo, you can create a new Snowflake Enterprise trial account and set up Travis to build it by setting these environment variables: -* `SNOWFLAKE_ACCOUNT` - The account name -* `SNOWFLAKE_USER` - A snowflake user for running tests. -* `SNOWFLAKE_PASSWORD` - Password for that user. -* `SNOWFLAKE_ROLE` - Needs to be ACCOUNTADMIN or similar. -* `SNOWFLAKE_REGION` - Default is us-west-2, set this if your snowflake account is in a different region. +## Advanced Debugging +If you want to build and test the provider locally there is a make target `make install-tf` that will build the provider binary and install it in a location that terraform can find. -You will also need to generate a Github API token and add the secret: +To debug the provider with a debugger: +1. Launch the provider with the `-debug` command line argument in your debugger session. Once the provider starts, it will print instructions on setting the `TF_REATTACH_PROVIDERS` environment variable. + ``` + Provider started. To attach Terraform CLI, set the TF_REATTACH_PROVIDERS environment variable with the following: -* `REVIEWDOG_GITHUB_API_TOKEN` - A token for reviewdog to use to access your github account with privileges to read/write discussion. + Command Prompt: set "TF_REATTACH_PROVIDERS={"registry.terraform.io/Snowflake-Labs/snowflake":{"Protocol":"grpc","ProtocolVersion":5,"Pid":35140,"Test":true,"Addr": {"Network":"tcp","String":"127.0.0.1:54706"}}}" + PowerShell: $env:TF_REATTACH_PROVIDERS='{"registry.terraform.io/Snowflake-Labs/snowflake":{"Protocol":"grpc","ProtocolVersion":5,"Pid":35140,"Test":true,"Addr":{"Network":"tcp","String":"127.0.0.1:54706"}}}' + ``` +2. Open a terminal where you will execute Terraform and set the `TF_REATTACH_PROVIDERS` environment variable using the command from the first step. +3. Run Terraform as usual from this terminal. Any breakpoints you set will halt execution and you can troubleshoot the provider from your debugger. -## Releasing +**Note**: The `TF_REATTACH_PROVIDERS` environment variable needs to be set every time you restart your debugger session as some values like the `Pid` or the TCP port will change with every execution. -## Running a release +For further instructions, please check the official [Terraform Plugin Development guide](https://www.terraform.io/plugin/debugging#starting-a-provider-in-debug-mode). -**Note: releases can only be done by those with keybase pgp keys allowed in the terraform registry.** +## Releasing Releases will be performed as needed, typically once every 1-2 weeks. If your change is more urgent and you need to use it sooner, use the commit hash. diff --git a/pkg/resources/saml_integration_acceptance_test.go b/pkg/resources/saml_integration_acceptance_test.go index 1705ed42d1..e2bfaf8bb8 100644 --- a/pkg/resources/saml_integration_acceptance_test.go +++ b/pkg/resources/saml_integration_acceptance_test.go @@ -26,9 +26,9 @@ func TestAcc_SamlIntegration(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_saml_integration.test_saml_int", "name", samlIntName), resource.TestCheckResourceAttr("snowflake_saml_integration.test_saml_int", "saml2_issuer", "test_issuer"), - resource.TestCheckResourceAttr("snowflake_saml_integration.test_saml_int", "saml2_sso_url", "https://testsamlissuer.com"), + resource.TestCheckResourceAttr("snowflake_saml_integration.test_saml_int", "saml2_sso_url", "https://samltest.id/saml/sp"), resource.TestCheckResourceAttr("snowflake_saml_integration.test_saml_int", "saml2_provider", "CUSTOM"), - resource.TestCheckResourceAttr("snowflake_saml_integration.test_saml_int", "saml2_x509_cert", "MIICYzCCAcygAwIBAgIBADANBgkqhkiG9w0BAQUFADAuMQswCQYDVQQGEwJVUzEMMAoGA1UEChMDSUJNMREwDwYDVQQLEwhMb2NhbCBDQTAeFw05OTEyMjIwNTAwMDBaFw0wMDEyMjMwNDU5NTlaMC4xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNJQk0xETAPBgNVBAsTCExvY2FsIENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD2bZEo7xGaX2/0GHkrNFZvlxBou9v1Jmt/PDiTMPve8r9FeJAQ0QdvFST/0JPQYD20rH0bimdDLgNdNyn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tPMUWgFDkgcI3QiV1lsKfBs1t1E2UA7ACFnlJZpEuBtwgivzo3VeitiSaF3Jxh25EY5/vABpcgQQRz3RH2l8MMKdRsxb8VT3yh2S+CX55s+cN67LiCPr6f2u+KS1iKfB9mWN6o2S4lcmo82HIBbsuXJV0oA1HrGMyyc4Y9nng/I8iuAp8or1JrWRHQ+8NzO85DWK0rtvtLPxkvw0HK32glyuOP/9F05Z7+tiVIgn67buC0EdoUm1RSpibqmB1ST2PikslOlVbJuy4Ah93wIDAQABo1gwVjA1BgNVHREELjAsgippcC0xNzItMzEtMjgtNjQudXMtd2VzdC0yLmNvbXB1dGUuaW50ZXJuYWwwHQYDVR0OBBYEFAdsTxYfulJ5yunYtgYJHC9IcevzMA0GCSqGSIb3DQEBCwUAA4IBgQB3J6i7KreiHL8NPMglfWLHk1PZOgvIEEpKL+GRebvcbyqgcuc3VVPylq70VvGqhJxp1q/mzLfraUiypzfWFGm9zfwIg0H5TqRZYEPTvgIhIICjaDWRwZBDJG8D5G/KoV60DlUG0crPBlIuCCr/SRa5ZoDQqvucTfr3Rx4Ha6koXFSjoSXllR+jn4GnInhm/WH137a+v35PUcffNxfuehoGn6i4YeXF3cwJK4e35cOFW+dLbnaLk+Ty7HOGvpw86h979C6mJ9qEHYgq9rQyzlSPbLZGZSgVcIezunOaOsWm81BsXRNNJjzHGCqKf8RMhd8oZP55+2/SVRBwnkGyUNCuDPrJcymC95ZT2NW/KeWkz28HF2i31xQmecT2r3lQRSM8acvOXQsNEDCDvJvCzJT9c2AnsnO24r6arPXs/UWAxOI+MjclXPLkLD6uTHV+Oo8XZ7bOjegD5hL6/bKUWnNMurQNGrmi/jvqsCFLDKftl7ajuxKjtodnSuwhoY7NQy8="), resource.TestCheckResourceAttrSet("snowflake_saml_integration.test_saml_int", "created_on"), resource.TestCheckResourceAttrSet("snowflake_saml_integration.test_saml_int", "saml2_snowflake_x509_cert"), resource.TestCheckResourceAttrSet("snowflake_saml_integration.test_saml_int", "saml2_snowflake_acs_url"), @@ -47,9 +47,9 @@ func samlIntegrationConfig(name string) string { resource "snowflake_saml_integration" "test_saml_int" { name = "%s" saml2_issuer = "test_issuer" - saml2_sso_url = "https://testsamlissuer.com" + saml2_sso_url = "https://samltest.id/saml/sp" saml2_provider = "CUSTOM" - saml2_x509_cert = "MIID2jCCA0MCAg39MA0GCSqGSIb3DQEBBQUAMIGbMQswCQYDVQQGEwJKUDEOMAwGA1UECBMFVG9reW8xEDAOBgNVBAcTB0NodW8ta3UxETAPBgNVBAoTCEZyYW5rNEREMRgwFgYDVQQLEw9XZWJDZXJ0IFN1cHBvcnQxGDAWBgNVBAMTD0ZyYW5rNEREIFdlYiBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBmcmFuazRkZC5jb20wHhcNMTIwODIyMDUyODAwWhcNMTcwODIxMDUyODAwWjBKMQswCQYDVQQGEwJKUDEOMAwGA1UECAwFVG9reW8xETAPBgNVBAoMCEZyYW5rNEREMRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCwvWITOLeyTbS1Q/UacqeILIK16UHLvSymIlbbiT7mpD4SMwB343xpIlXN64fC0Y1ylT6LLeX4St7AcJrGIV3AMmJcsDsNzgo577LqtNvnOkLH0GojisFEKQiREX6gOgq9tWSqwaENccTEsAXuV6AQ1ST+G16s00iN92hjX9V/V66snRwTsJ/p4WRpLSdAj4272hiM19qIg9zrh92e2rQy7E/UShW4gpOrhg2f6fcCBm+aXIga+qxaSLchcDUvPXrpIxTd/OWQ23QhvIEzkGbPlBA8J7Nw9KCyaxbYMBFb1i0lBjwKLjmcoihiI7PVthAOu/B71D2hKcFjKpfv4D1Uam/0VumKwhwuhZVNjLq1BR1FKRJ1CioLG4wCTr0LVgtvvUyhFrS+3PdUR0T5HlAQWPMyQDHgCpbOHW0wc0hbuNeO/lS82LjieGNFxKmMBFF9lsN2zsA6Qw32Xkb2/EFltXCtpuOwVztdk4MD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4lcmo82HIBbsuXJV0oA1HrGMyyc4Y9nng/I8iuAp8or1JrWRHQ+8NzO85DWK0rtvtLPxkvw0HK32glyuOP/9F05Z7+tiVIgn67buC0EdoUm1RSpibqmB1ST2PikslOlVbJuy4Ah93wIDAQABo1gwVjA1BgNVHREELjAsgippcC0xNzItMzEtMjgtNjQudXMtd2VzdC0yLmNvbXB1dGUuaW50ZXJuYWwwHQYDVR0OBBYEFAdsTxYfulJ5yunYtgYJHC9IcevzMA0GCSqGSIb3DQEBCwUAA4IBgQB3J6i7KreiHL8NPMglfWLHk1PZOgvIEEpKL+GRebvcbyqgcuc3VVPylq70VvGqhJxp1q/mzLfraUiypzfWFGm9zfwIg0H5TqRZYEPTvgIhIICjaDWRwZBDJG8D5G/KoV60DlUG0crPBlIuCCr/SRa5ZoDQqvucTfr3Rx4Ha6koXFSjoSXllR+jn4GnInhm/WH137a+v35PUcffNxfuehoGn6i4YeXF3cwJK4e35cOFW+dLbnaLk+Ty7HOGvpw86h979C6mJ9qEHYgq9rQyzlSPbLZGZSgVcIezunOaOsWm81BsXRNNJjzHGCqKf8RMhd8oZP55+2/SVRBwnkGyUNCuDPrJcymC95ZT2NW/KeWkz28HF2i31xQmecT2r3lQRSM8acvOXQsNEDCDvJvCzJT9c2AnsnO24r6arPXs/UWAxOI+MjclXPLkLD6uTHV+Oo8XZ7bOjegD5hL6/bKUWnNMurQNGrmi/jvqsCFLDKftl7ajuxKjtodnSuwhoY7NQy8=" enabled = false } `, name) diff --git a/pkg/resources/warehouse_acceptance_test.go b/pkg/resources/warehouse_acceptance_test.go index 40967cc316..f2ea4c9b67 100644 --- a/pkg/resources/warehouse_acceptance_test.go +++ b/pkg/resources/warehouse_acceptance_test.go @@ -56,7 +56,7 @@ func TestAcc_Warehouse(t *testing.T) { ResourceName: "snowflake_warehouse.w", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"initially_suspended", "wait_for_provisioning"}, + ImportStateVerifyIgnore: []string{"initially_suspended", "wait_for_provisioning", "query_acceleration_max_scale_factor"}, }, }, })