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 table azure_sql_database. closes #89 #93

Merged
merged 4 commits into from
Apr 22, 2021
Merged

Add table azure_sql_database. closes #89 #93

merged 4 commits into from
Apr 22, 2021

Conversation

sayan133
Copy link
Contributor

@sayan133 sayan133 commented Apr 13, 2021

Integration test logs

Logs
No env file present for the current environment:  staging 
 Falling back to .env config
No env file present for the current environment:  staging
customEnv TURBOT_TEST_EXPECTED_TIMEOUT undefined

SETUP: tests/azure_sql_database []

PRETEST: tests/azure_sql_database

TEST: tests/azure_sql_database
Running terraform
azurerm_resource_group.named_test_resource: Creating...
azurerm_resource_group.named_test_resource: Creation complete after 2s [id=/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685]
azurerm_sql_server.named_test_resource: Creating...
azurerm_sql_server.named_test_resource: Still creating... [10s elapsed]
azurerm_sql_server.named_test_resource: Still creating... [20s elapsed]
azurerm_sql_server.named_test_resource: Still creating... [30s elapsed]
azurerm_sql_server.named_test_resource: Still creating... [40s elapsed]
azurerm_sql_server.named_test_resource: Still creating... [50s elapsed]
azurerm_sql_server.named_test_resource: Still creating... [1m0s elapsed]
azurerm_sql_server.named_test_resource: Still creating... [1m10s elapsed]
azurerm_sql_server.named_test_resource: Creation complete after 1m15s [id=/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685]
azurerm_sql_database.named_test_resource: Creating...
azurerm_sql_database.named_test_resource: Still creating... [10s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [20s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [30s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [40s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [50s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [1m0s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [1m10s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [1m20s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [1m30s elapsed]
azurerm_sql_database.named_test_resource: Still creating... [1m40s elapsed]
azurerm_sql_database.named_test_resource: Creation complete after 1m45s [id=/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685]

Warning: Deprecated Resource

The null_data_source was historically used to construct intermediate values to
re-use elsewhere in configuration, the same can now be achieved using locals


Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

resource_aka = "azure:///subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685"
resource_aka_lower = "azure:///subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourcegroups/turbottest8685/providers/microsoft.sql/servers/turbottest8685/databases/turbottest8685"
resource_creation_date = "2021-04-15T13:52:21.53Z"
resource_default_secondary_location = "West US"
resource_id = "/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685"
resource_location = "East US"
resource_name = "turbottest8685"
resource_region = "east us"
subscription_id = "cd4401c4-3cc8-4565-a594-839c1e345f1e"

Running SQL query: test-get-query.sql
[
  {
    "akas": [
      "azure:///subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685",
      "azure:///subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourcegroups/turbottest8685/providers/microsoft.sql/servers/turbottest8685/databases/turbottest8685"
    ],
    "containment_state": 2,
    "default_secondary_location": "West US",
    "earliest_restore_date": null,
    "edition": "GeneralPurpose",
    "elastic_pool_name": null,
    "id": "/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685",
    "location": "East US",
    "max_size_bytes": "34359738368",
    "name": "turbottest8685",
    "region": "east us",
    "requested_service_objective_name": "GP_Gen5_2",
    "resource_group": "turbottest8685",
    "server_name": "turbottest8685",
    "service_level_objective": "GP_Gen5_2",
    "status": "Online",
    "subscription_id": "cd4401c4-3cc8-4565-a594-839c1e345f1e",
    "tags": {
      "foo": "bar"
    },
    "title": "turbottest8685",
    "transparent_data_encryption": {
      "status": "Enabled"
    },
    "type": "Microsoft.Sql/servers/databases",
    "zone_redundant": false
  }
]
✔ PASSED

Running SQL query: test-hydrate-query.sql
[
  {
    "id": "/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685",
    "name": "turbottest8685",
    "server_name": "turbottest8685",
    "transparent_data_encryption": {
      "status": "Enabled"
    }
  }
]
✔ PASSED

Running SQL query: test-list-query.sql
[
  {
    "id": "/subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685",
    "location": "East US",
    "name": "turbottest8685",
    "resource_group": "turbottest8685",
    "server_name": "turbottest8685"
  }
]
✔ PASSED

Running SQL query: test-not-found-query.sql
null
✔ PASSED

Running SQL query: test-turbot-query.sql
[
  {
    "akas": [
      "azure:///subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbottest8685/providers/Microsoft.Sql/servers/turbottest8685/databases/turbottest8685",
      "azure:///subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourcegroups/turbottest8685/providers/microsoft.sql/servers/turbottest8685/databases/turbottest8685"
    ],
    "name": "turbottest8685",
    "tags": {
      "foo": "bar"
    },
    "title": "turbottest8685"
  }
]
✔ PASSED

POSTTEST: tests/azure_sql_database

TEARDOWN: tests/azure_sql_database

SUMMARY:

1/1 passed.

Example query results

Results

Basic info

select
  name,
  id,
  server_name,
  location,
  edition
from
  azure_sql_database;
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+----------+
| name           | id                                                                                                                                                   | server_name    | location | edition  |
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+----------+
| master         | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/test-steampipe/databases/master         | test-steampipe | East US  | "System" |
| test-steampipe | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/test-steampipe/databases/test-steampipe | test-steampipe | East US  | "Basic"  |
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+----------+

List databases for a specific server

select
  name,
  id,
  server_name,
  location,
  edition
from
  azure_sql_database
where
  server_name = 'test-steampipe';
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+---------+
| name           | id                                                                                                                                                   | server_name    | location | edition |
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+---------+
| test-steampipe | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/test-steampipe/databases/test-steampipe | test-steampipe | East US  | "Basic" |
| master         | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/test-steampipe/databases/master         | test-steampipe | East US  | "Basic" |
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+---------+

List databases having system edition

select
  name,
  id,
  server_name,
  location,
  edition
from
  azure_sql_database
where
  edition = 'Basic';
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+---------+
| name           | id                                                                                                                                                   | server_name    | location | edition |
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+---------+
| test-steampipe | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/test-steampipe/databases/test-steampipe | test-steampipe | East US  | Basic   |
| master         | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/test-steampipe/databases/master         | test-steampipe | East US  | Basic   |
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------+---------+

List databases which are not online

select
  name,
  id,
  server_name,
  location,
  edition,
  status
from
  azure_sql_database
where
  status != 'Online';
+------+----+-------------+----------+---------+--------+
| name | id | server_name | location | edition | status |
+------+----+-------------+----------+---------+--------+
+------+----+-------------+----------+---------+--------+

List databases which are not encrypted

select
  name,
  id,
  server_name,
  location,
  edition,
  transparent_data_encryption ->> 'status' as encryption_status
from
  azure_sql_database
where
  transparent_data_encryption ->> 'status' != 'Enabled';
+--------+------------------------------------------------------------------------------------------------------------------------------------+-------------+----------+---------+-------------------+
| name   | id                                                                                                                                 | server_name | location | edition | encryption_status |
+--------+------------------------------------------------------------------------------------------------------------------------------------+-------------+----------+---------+-------------------+
| master | /subscriptions/cd4401c4-3cc8-4565-a594-839c1e345f1e/resourceGroups/turbot_rg/providers/Microsoft.Sql/servers/stmp/databases/master | stmp        | East US  | Basic   | Disabled          |
+--------+------------------------------------------------------------------------------------------------------------------------------------+-------------+----------+---------+-------------------+

List databases created before last 7 days

select
  name,
  id,
  server_name,
  location,
  creation_date
from
  azure_sql_database
where
  creation_date < (current_date - 7);
+------+----+-------------+----------+---------------+
| name | id | server_name | location | creation_date |
+------+----+-------------+----------+---------------+
+------+----+-------------+----------+---------------+

@sayan133 sayan133 self-assigned this Apr 13, 2021
@sayan133 sayan133 marked this pull request as ready for review April 15, 2021 14:01
@sayan133 sayan133 requested a review from Paulami30 April 15, 2021 14:01
azure/plugin.go Outdated
@@ -57,6 +57,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"azure_role_definition": tableAzureIamRoleDefinition(ctx),
"azure_route_table": tableAzureRouteTable(ctx),
"azure_sql_server": tableAzureSQLServer(ctx),
"azure_sql_database": tableAzureSqlDatabase(ctx),
Copy link
Contributor

Choose a reason for hiding this comment

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

fix indentation

return nil, nil
}

//// TRANSFORM FUNCTIONS
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//// TRANSFORM FUNCTIONS
//// TRANSFORM FUNCTION

@@ -0,0 +1,100 @@
# Table: azure_sql_database

An Azure SQL Database is an intelligent, scalable, relational database service built for the cloud. Optimise performance and durability with automated, AI-powered features that are always up to date.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
An Azure SQL Database is an intelligent, scalable, relational database service built for the cloud. Optimise performance and durability with automated, AI-powered features that are always up to date.
An Azure SQL Database is an intelligent, scalable, relational database service built for the cloud.

```


### List databases which are online
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### List databases which are online
### List databases which are not online

```


### List databases which are encrypted
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
### List databases which are encrypted
### List databases which are not encrypted

Copy link
Contributor

Choose a reason for hiding this comment

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

modify the queries accordingly

@Paulami30
Copy link
Contributor

LGTM

@Paulami30 Paulami30 requested a review from rajlearner17 April 16, 2021 14:48
Copy link
Contributor

@rajlearner17 rajlearner17 left a comment

Choose a reason for hiding this comment

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

LGTM

@cbruno10 cbruno10 merged commit df16912 into main Apr 22, 2021
@cbruno10 cbruno10 deleted the issue-89 branch April 22, 2021 19:05
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.

4 participants