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

User Story 60501: 101-aks-cluster #218

Closed

Conversation

TomArcherMsft
Copy link
Collaborator

Part of POC to test generating sample code and articles using OpenAI.

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 @TomArcherMsft for opening this pr, could we use tls_private_key resource to generate the ssh key?

parent_id = azurerm_resource_group.rg.id
}

resource "azapi_resource_action" "ssh_public_key_gen" {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend tls_private_key resource:

# RSA key of size 4096 bits
resource "tls_private_key" "rsa_4096" {
  algorithm = "RSA"
  rsa_bits  = 4096
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi, @lonegunmanb. I used the AzAPI as that is something @grayzu recommended in an email thread with all of us. Maybe we need to reengage on the email thread or figure it out here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Although the tls provider will do the trick, I think making use of the Azure functionality which will provide SSH certificates that can be used in production environments is a better way to show this functionality. According to the docs, the tls provider is not recommended for prod use.

admin_username = var.linux_admin_username

ssh_key {
key_data = jsondecode(azapi_resource_action.ssh_public_key_gen.output)["publicKey"]
Copy link
Member

Choose a reason for hiding this comment

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

If we use tls_private_key resource, then the key_data could be:

key_data = tls_private_key.rsa_4096.public_key_openssh

value = azurerm_resource_group.rg.name
}

output "ssh_key_name" {
Copy link
Member

Choose a reason for hiding this comment

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

We can export the private key:

output "ssh_private_key_openssh" {
  sensitive = true
  value = tls_private_key.rsa_4096.private_key_openssh
}

output "ssh_private_key_pem" {
  sensitive = true
  value = tls_private_key.rsa_4096.private_key_pem
}

terraform {
required_version = ">=1.0"
required_providers {
azapi = {
Copy link
Member

Choose a reason for hiding this comment

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

We can use tls provider here:

tls = {
      source = "hashicorp/tls"
      version = "~>4.0"
    }

@TomArcherMsft TomArcherMsft temporarily deployed to acctests April 23, 2023 01:12 — with GitHub Actions Inactive
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.

LGTM! @grayzu WDYT?

@lonegunmanb lonegunmanb requested a review from grayzu May 9, 2023 00:01
Copy link
Contributor

@grayzu grayzu left a comment

Choose a reason for hiding this comment

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

I responded to lonegunmanb's suggestion to use tls provider. Everything else looks great.

parent_id = azurerm_resource_group.rg.id
}

resource "azapi_resource_action" "ssh_public_key_gen" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although the tls provider will do the trick, I think making use of the Azure functionality which will provide SSH certificates that can be used in production environments is a better way to show this functionality. According to the docs, the tls provider is not recommended for prod use.

@TomArcherMsft
Copy link
Collaborator Author

TomArcherMsft commented May 15, 2023

@grayzu @lonegunmanb

In a more recent PR, I put the SSH-creation code in a separate file (ssh.tf). I like doing that as it's isolates the SSH creation & AzAPI usage and reduces code in main.tf. Should we use that pattern as the standard? If so, I'll make the change to this PR.

@lonegunmanb
Copy link
Member

@grayzu @lonegunmanb

In a more recent PR, I put the SSH-creation code in a separate file (ssh.tf). I like doing that as it's isolates the SSH creation & AzAPI usage and reduces code in main.tf. Should we use that pattern as the standard? If so, I'll make the change to this PR.

As long as we've agreed on a working pattern I think it's ok to apply the pattern on this repo.

@TomArcherMsft
Copy link
Collaborator Author

@stemaMSFT @lonegunmanb This PR is ready to review.

Copy link

@Jingwei-MS Jingwei-MS left a comment

Choose a reason for hiding this comment

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

LGTM~

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.

Hi @TomArcherMsft thanks for the update, it looks this pr's base commit is too old so the changed files scope that the pipeline calculated was wrong. Would you please rebase your branch to the latest master branch and try again? Thanks!

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