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

feat(aks): add microsoft defender support #232

Merged
merged 4 commits into from
Sep 7, 2022

Conversation

eyenx
Copy link
Contributor

@eyenx eyenx commented Aug 23, 2022

Changes proposed in the pull request:

Adds support for a microsoft_defender block introduced with hashicorp/terraform-provider-azurerm#16218

Signed-off-by: Toni Tauro [email protected]

@eyenx
Copy link
Contributor Author

eyenx commented Aug 27, 2022

@lonegunmanb can't run the test anymore.

Always getting same errors:

INFO: Styling Terraform configurations...
INFO: Done!
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Unsupported block type

  on main.tf line 5:
   5: moved {

Blocks of type "moved" are not expected here.


Error: Unsupported block type

  on main.tf line 178, in resource "azurerm_kubernetes_cluster" "main":
 178:     precondition {

Blocks of type "precondition" are not expected here.


Error: Unsupported block type

  on main.tf line 182, in resource "azurerm_kubernetes_cluster" "main":
 182:     precondition {

Blocks of type "precondition" are not expected here.


Error: Unsupported argument

  on variables.tf line 57, in variable "agents_pool_name":
  57:   nullable    = false

The terraform-test image we are using is quite outdated (versoin 0.14.4). Could it be because of that?

@eyenx
Copy link
Contributor Author

eyenx commented Aug 27, 2022

I now created my own mcr.microsoft.com/terraform-test:1.2.5 by grabbing the https://github.com/azure/terraform-test repo and adjusting some vars.

I was able to run the rake build, but not the tests:

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
INFO: Linting Terraform configurations...
INFO: Done!
INFO: Styling Terraform README...
INFO: Done!
INFO: Styling Terraform fixture configurations...
INFO: Done!
go: cannot find main module, but found Gopkg.lock in /go/src/terraform-azurerm-aks
        to create a module there, run:
        go mod init
rake aborted!
ERROR: Go test failed!

/go/src/terraform-azurerm-aks/Rakefile:45:in `block (2 levels) in <top (required)>'
Tasks: TOP => full => e2e => integration:test
(See full trace by running task with --trace)

@lonegunmanb
Copy link
Member

I now created my own mcr.microsoft.com/terraform-test:1.2.5 by grabbing the https://github.com/azure/terraform-test repo and adjusting some vars.

I was able to run the rake build, but not the tests:

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
INFO: Linting Terraform configurations...
INFO: Done!
INFO: Styling Terraform README...
INFO: Done!
INFO: Styling Terraform fixture configurations...
INFO: Done!
go: cannot find main module, but found Gopkg.lock in /go/src/terraform-azurerm-aks
        to create a module there, run:
        go mod init
rake aborted!
ERROR: Go test failed!

/go/src/terraform-azurerm-aks/Rakefile:45:in `block (2 levels) in <top (required)>'
Tasks: TOP => full => e2e => integration:test
(See full trace by running task with --trace)

Thanks @eyenx for opening this Pr! The dockerfile and docker imaged described in readme file is outdated and no longer been maintained, we're working on a new CI pipeline and we're close to a release (We'll release v6.0.0 with this new CI pipeline). I'm not going to update this mcr.microsoft.com/terraform-test image and rake tests since they'll be replaced very soon. If you're interested in this new CI, you can try it on my personal branch, we have instructions in readme file on how to run the pr checks and acc tests for our module. For this pr please give me some time to review and test with new CI on my machine. Once we've solved the issues that block our CI pipeline, we'll introduce this pipeline into some legacy azurerm Terraform modules. Thanks for your understanding.

main.tf Outdated
@@ -166,6 +166,14 @@ resource "azurerm_kubernetes_cluster" "main" {
}
}

dynamic "microsoft_defender" {
Copy link
Member

Choose a reason for hiding this comment

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

Could we move this block to line 144 please? We're sorting arguments(assignments with equal symbol) and blocks in resource block are sorted in the following order:

  • count and for_each
  • Required arguments in lexicographical order
  • Optional arguments in lexicographical order
  • Required blocks in lexicographical order
  • Optional blocks in lexicographical order
  • depends_on, then lifecycle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gonna do this ra

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

variables.tf Outdated
}

variable "microsoft_defender_enabled" {
Copy link
Member

Choose a reason for hiding this comment

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

Could we move this block to line 262 please? We are sorting variables in the following order:

  • Required variables in lexicographical order(variables without default value)
  • Optional variables in lexicographical order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gonna do this ra

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

main.tf Outdated
for_each = var.microsoft_defender_enabled ? ["microsoft_defender"] : []

content {
log_analytics_workspace_id = var.log_analytics_workspace_id == null ? azurerm_log_analytics_workspace.main[0].id : var.log_analytics_workspace.id
Copy link
Member

Choose a reason for hiding this comment

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

Hi @eyenx , there might be a typo here since we have not var.log_analytics_workspace_id. Could we change this line to the following line?:

log_analytics_workspace_id = coalesce(try(var.log_analytics_workspace.id, null), azurerm_log_analytics_workspace.main[0].id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Sry for late reply

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @eyenx, LGTM

@lonegunmanb lonegunmanb merged commit be1cbdb into Azure:master Sep 7, 2022
@eyenx eyenx deleted the feat/add-microsoft-defender-block branch September 7, 2022 21:23
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.

2 participants