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

New Resource: azurerm_sql_active_directory_administrator #765

Merged
merged 9 commits into from
Mar 2, 2018
Merged

New Resource: azurerm_sql_active_directory_administrator #765

merged 9 commits into from
Mar 2, 2018

Conversation

simongh
Copy link
Contributor

@simongh simongh commented Jan 29, 2018

I've added the ability to set the AD administrator on SQL servers.

This is my first attempt at using GO and writing anything for Terraform, so I've probably made egregious mistakes.

It appeared to work when I tried it out on my Azure.

@tombuildsstuff tombuildsstuff added this to the 1.1.3 milestone Feb 16, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @simongh

Thanks for this PR - apologies for the delay in reviewing this!

I've taken a look through and left some comments inline, but this is off to a good start. If we can fix up the issues raised in the comments and some documentation - this otherwise looks good to kick off the tests. Regarding documentation, this consists of a link in the sidebar and a documentation page similar to this one.

Thanks!

"tenant_id": {
Type: schema.TypeString,
Required: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some validation for this to ensure it's a valid UUID? we can use:

ValidateFunc: validateUUID,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added suggested validator. This value can be updated.


"object_id": {
Type: schema.TypeString,
Required: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some validation for this to ensure it's a valid UUID? we can use:

ValidateFunc: validateUUID,

also, can this value be updated? if not, this would be better as ForceNew: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added validator. This value can be updated


"resource_group_name": resourceGroupNameSchema(),

"login": {
Copy link
Contributor

Choose a reason for hiding this comment

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

would this be better as username? also, can this value be updated? if not, this would be better as ForceNew: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

login matches up with the Azure API. They don't tend to use username very much, as this could also be a group name.

I'm not precious about it either way though

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 that's fair - let's leave this as-is

resp, error := client.Get(ctx, resGroup, serverName, administratorName)
if error != nil {
return error
}
Copy link
Contributor

Choose a reason for hiding this comment

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

minor can we change error -> err to match the convention here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to match conventions

uuid "github.com/satori/go.uuid"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
//"github.com/hashicorp/terraform/helper/validation"
//"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor can we remove these unused imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Create: resourceArmSqlAdministratorCreateUpdate,
Read: resourceArmSqlAdministratorRead,
Update: resourceArmSqlAdministratorCreateUpdate,
Delete: resourceArmSqlAdministratorDelete,
Copy link
Contributor

Choose a reason for hiding this comment

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

could we update the function name + these prefixes to resourceArmSqlActiveDirectoryAdministrator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed as requested


serverName := d.Get("server_name").(string)
resGroup := d.Get("resource_group_name").(string)
administratorName := "activeDirectory"
Copy link
Contributor

Choose a reason for hiding this comment

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

note when #825 is resolved we shouldn't need this field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

presuming I don't need to do anything here?

Copy link
Contributor

@tombuildsstuff tombuildsstuff Feb 28, 2018

Choose a reason for hiding this comment

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

indeed - we'll take care of those changes once it's merged in (it's more a future TODO for us 😄)

login = "sqladmin"
tenant_id = "${data.azurerm_client_config.current.tenant_id}"
object_id = "${data.azurerm_client_config.current.client_id}"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

minor could we make the spacing consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

resource_group_name = "${azurerm_resource_group.test.name}"
login = "sqladmin2"
tenant_id = "${data.azurerm_client_config.current.tenant_id}"
object_id = "${data.azurerm_client_config.current.client_id}"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor could we fix the spacing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Delete: resourceArmSqlAdministratorDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

given we've supported import - can we add an import test for this resource? here's an example of how we do that https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/azurerm/import_arm_mysql_server_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I've implemented this. i'm getting a "filename too long" error, which makes it tricky to test this is working at all

Copy link
Contributor

Choose a reason for hiding this comment

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

no worries, I can kick off the tests and take a look. Out of interest (I'm assuming you're running on Windows) - do you have the unlimited filename length Windows feature enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't & I have now, but it seems VS Code still complains.

@simongh
Copy link
Contributor Author

simongh commented Feb 22, 2018

I do this normally at work, but just checking here before I do it. If I rebase my branch with these changes onto master, it's not going to mess the pull request up is it?

@tombuildsstuff
Copy link
Contributor

I do this normally at work, but just checking here before I do it. If I rebase my branch with these changes onto master, it's not going to mess the pull request up is it?

@simongh nope, it should be fine :)

@tombuildsstuff tombuildsstuff modified the milestones: 1.1.3, 1.1.4 Feb 28, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @simongh

Thanks for pushing those changes - I've taken a look through and this mostly LGTM. I've picked out a few minor issues which I'll push a commit to fix so that we can get this merged (I hope you don't mind) and then kick off the tests - but otherwise we should be good to merge this :)

Thanks!

ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{},
Copy link
Contributor

Choose a reason for hiding this comment

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

minor we can actually remove this, since it's empty


## Import

A SQL Active Directory Administratir can be imported using the `resource id`, e.g.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor Administratir -> Administrator


* `server_name` - (Required) The name of the SQL Server on which to set the administrator

* `resource_group_name` - (Required) The name of the resource group for the SQL server.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we append Changing this forces a new resource to be created. to this?


The following arguments are supported:

* `server_name` - (Required) The name of the SQL Server on which to set the administrator
Copy link
Contributor

Choose a reason for hiding this comment

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

can we append Changing this forces a new resource to be created. to this?

Add a Active Directory administrator to a SQL server
---

# azurerm\_sql\_active\_directory\_administrator
Copy link
Contributor

Choose a reason for hiding this comment

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

minor we don't need the backslashes here

@tombuildsstuff tombuildsstuff changed the title Sql AD Administrator New Resource: azurerm_sql_active_directory_administrator Mar 2, 2018
@tombuildsstuff
Copy link
Contributor

Tests pass:

$ acctests azurerm TestAccAzureRMSqlAdministrator_
=== RUN   TestAccAzureRMSqlAdministrator_importBasic
--- PASS: TestAccAzureRMSqlAdministrator_importBasic (176.72s)
=== RUN   TestAccAzureRMSqlAdministrator_basic
--- PASS: TestAccAzureRMSqlAdministrator_basic (172.36s)
=== RUN   TestAccAzureRMSqlAdministrator_disappears
--- PASS: TestAccAzureRMSqlAdministrator_disappears (174.91s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	524.033s

@tombuildsstuff tombuildsstuff merged commit f6429a1 into hashicorp:master Mar 2, 2018
tombuildsstuff added a commit that referenced this pull request Mar 2, 2018
@simongh
Copy link
Contributor Author

simongh commented Mar 3, 2018

That's all good. Happy to have contributed.

@simongh simongh deleted the sql-admin branch March 3, 2018 11:30
@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource service/mssql Microsoft SQL Server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants