Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure SQL Managed Instance Module #1307

Merged
merged 17 commits into from
Jul 7, 2023

Conversation

sweanan
Copy link

@sweanan sweanan commented Jun 14, 2023

Description

Fixes #1279

This PR adds below:
Examples SQL MI : examples/azure/sqlmanagedinstance
AzureSQL Managed Instance Module under: modules/azure/sqlmanagedinstance*
Corresponding tests are added: tests/azure/terraform-azure-sqlmanagedinstanceexample

NOTE:
As described in the README.md for sqlmanagedinstance, the deployment for this module take more that 4-6 hours as per documents, so the tests are excluded from the workflow by adding a tag !azure so that this test file will not be picked up from the ci workflow

Test with sqlmanaged instance long running:
https://github.com/sweanan/terratest/actions/runs/5322721656/jobs/9639554889
TestTerraformAzureSQLManagedInstanceExample 2023-06-20T14:04:18Z logger.go:66: azurerm_mssql_managed_instance.sqlmi_mi: Still creating... [1h5m20s elapsed] TestTerraformAzureSQLManagedInstanceExample 2023-06-20T14:04:28Z logger.go:66: azurerm_mssql_managed_instance.sqlmi_mi: Still creating... [1h5m30s elapsed]

Test excluding sqlmanaged instance : terraform_azure_sqlmanagedinstance_example_test.go
https://github.com/sweanan/terratest/actions/runs/5350335787/jobs/9702803292

@HadwaAbdelhalem
Copy link
Contributor

Hi @sweanan can you drop a link for the CI execution on the PR branch.?

t.Parallel()

uniquePostfix := strings.ToLower(random.UniqueId())
expectedLocation := "West US2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be westus2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it

@sweanan
Copy link
Author

sweanan commented Jun 20, 2023

[Microsoft CI Bot] TL;DR; failure 🤦

You can check the status of the CI Pipeline logs here ; https://github.com/sweanan/terratest/actions/runs/5322652361

@@ -0,0 +1,63 @@
// SQL Managed Instance takes 6-8 hours for deployment, Exclude this from the worflow by naming it as *_testlong.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename the file to a be a valid test file 'sql_mangedinstace_test' and since get rid of all the tags with a minor change to the azure ci workflow to run tests based on the azure tag this would exclude the test from getting executed by using 'go test ./azure/* -v -timeout 90m --tags=azure'

go test ./azure/* -v -timeout 90m

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Hadwa updated it

@sweanan
Copy link
Author

sweanan commented Jun 22, 2023

[Microsoft CI Bot] TL;DR; failure 🤦

You can check the status of the CI Pipeline logs here ; https://github.com/sweanan/terratest/actions/runs/5350335787

Copy link
Contributor

@HadwaAbdelhalem HadwaAbdelhalem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sweanan ,LGTM!

managedInstanceName := ""
subscriptionID := ""

_, err := GetManagedInstanceE(t, subscriptionID, resGroupName, managedInstanceName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modules/azure/sql_managedinstance_test.go:39:65: too many arguments in call to GetManagedInstanceE
	have (*"testing".T, string, string, string)
	want (string, string, string)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it

@@ -0,0 +1,67 @@
//go:build !azure
// +build !azure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should be used same build parameters as for other azure tests

//go:build azure
// +build azure

Now, the regular CICD test job tries to run TestTerraformAzureSQLManagedInstanceExample and fails since az is not configured, other Azure tests aren't attempted to be executed

TestTerraformAzureSQLManagedInstanceExample 2023-06-25T21:29:15Z logger.go:66: ╵
TestTerraformAzureSQLManagedInstanceExample 2023-06-25T21:29:15Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; ╷
│ Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.
│ 
│   with provider["registry.terraform.io/hashicorp/azurerm"],
│   on main.tf line 12, in provider "azurerm":
│   12: provider "azurerm" {
│ 
╵}
    apply.go:15: 
        	Error Trace:	/home/circleci/project/test/azure/apply.go:15
        	            				/home/circleci/project/test/azure/terraform_azure_sqlmanagedinstance_example_test.go:46
        	Error:      	Received unexpected error:
        	            	FatalError{Underlying: error while running command: exit status 1; ╷
        	            	│ Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.
        	            	│ 
        	            	│   with provider["registry.terraform.io/hashicorp/azurerm"],
        	            	│   on main.tf line 12, in provider "azurerm":
        	            	│   12: provider "azurerm" {
        	            	│ 
        	            	╵}
        	Test:       	TestTerraformAzureSQLManagedInstanceExample

circle-test.txt

References:

https://github.com/gruntwork-io/terratest/blob/master/test/azure/terraform_azure_aci_example_test.go#L2

Copy link
Author

@sweanan sweanan Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @denis256, just a quick question, Can you please confirm, the workflow you are triggering is by using the .circleci/config.yml correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @denis256, looking at the circleci yaml file, I see that the azure tests are only compiled and not executed. I am not sure which part of the workflow triggered the execution of the azure tests. Can you please point me to the test stage/task where is got triggered.

Also can you share how/where a subset of the tests are mared as short? I see in the log file you shared earlier that the test cmd is using the -short flag ' go test -v -timeout 45m -parallel 128 -p 1 ./... -short'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step:

 - run: run-go-tests --packages "-p 1 ./..." | tee /tmp/logs/test_output.log

Included execution of TestTerraformAzureSQLManagedInstanceExample

image

I suspect it is because of(I need to do more tests to validate):

//go:build !azure
// +build !azure

Other tests have:

//go:build azure
// +build azure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/gruntwork-io/terratest/tree/add-sqlmi-module-azure-test
I set

//go:build azure
// +build azure

and TestTerraformAzureSQLManagedInstanceExample wasn't executed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denis256 I updated the PR to skip the test for the short executions, and update the tags as well. Testing locally the test has not been picked up by the go test cmd. please take a look when you get a chance and share the Circle ci log file as well.

@sweanan
Copy link
Author

sweanan commented Jul 5, 2023

[Microsoft CI Bot] TL;DR; failure 🤦

You can check the status of the CI Pipeline logs here ; https://github.com/sweanan/terratest/actions/runs/5469099387

@sweanan
Copy link
Author

sweanan commented Jul 5, 2023

[Microsoft CI Bot] TL;DR; failure 🤦

You can check the status of the CI Pipeline logs here ; https://github.com/sweanan/terratest/actions/runs/5469531305

@denis256
Copy link
Member

denis256 commented Jul 6, 2023

Hi, looks like imports should be fixed...

[INFO] Initializing environment for https://github.com/gruntwork-io/pre-commit.
goimports................................................................Failed
- hook id: goimports
- files were modified by this hook

test/azure/terraform_azure_sqlmanagedinstance_example_test.go

Terraform fmt............................................................Passed
test-interfaces-used.....................................................Passed

Copy link
Member

@denis256 denis256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing tests aren't related to implemented changes, most of tests I already fixed in master

@denis256 denis256 merged commit d58da78 into gruntwork-io:master Jul 7, 2023
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Azure SQL Managed Instance Module
3 participants