Terraform lab question 6(need ans)

The error in the configuration is inside the resource block for the tls_private_key type resource.
It contains the configuration that we needed for generating rsa type key…

Inspect the resource block and fix the issue.

Did you refer to the hint or the solution in the lab?

Am also stuck at this lab(Lab:- Terraform Commands, Question number 6) below is the error msg am getting
Please advise on this


Error: Provider produced inconsistent final plan

│ When expanding the plan for tls_cert_request.csr to include new values learned so far during apply, provider
│ “Terraform Registry” produced an invalid new value for .private_key_pem: inconsistent values
│ for sensitive attribute.

│ This is a bug in the provider, which should be reported in the provider’s own issue tracker.


Do you have a link to the lab? Also paste your Terraform code in a Codeblock </> here.

link of Lab
Terraform Basics Training Course | KodeKloud

below is the Code
</>
resource “local_file” “key_data” {
filename = “/tmp/.pki/private_key.pem”
content = tls_private_key.private_key.private_key_pem
file_permission = “0400”
}
resource “tls_private_key” “private_key” {
algorithm = “RSA”
rsa_bits = 2048
ecdsa_curve = “P384”
}
resource “tls_cert_request” “csr” {
private_key_pem = file(“/tmp/.pki/private_key.pem”)
depends_on = [ local_file.key_data ]

subject {
common_name = “flexit.com
organization = “FlexIT Consulting Services”
}
}
</>

link of Lab terminal
https://terminal-e72ac6143dbf4aef.labs.kodekloud.com/?folder=/root

Hi, on the menu bar is an icon that looks like </> use that to paste code. Also paste a link to the lab, not the terminal. Also paste the error.

I checked your Terraform code. You cannot create a file and read it back in the same Terrafrom code, that is not supported by Terraform. You should instead use the private_key_pem attribute from the tls_private_key resource.

Like so:

resource "local_file" "key_data" {
  filename        = "/tmp/.pki/private_key.pem"
  content         = tls_private_key.private_key.private_key_pem
  file_permission = "0400"
}
resource "tls_private_key" "private_key" {
  algorithm   = "RSA"
  rsa_bits    = 2048
  ecdsa_curve = "P384"
}
resource "tls_cert_request" "csr" {
  private_key_pem = tls_private_key.private_key.private_key_pem
  depends_on      = [local_file.key_data]

  subject {
    common_name  = "flexit.com"
    organization = "FlexIT Consulting Services"
  }
}

thank you, will check this again

The hint is not reflecting towards the right solution, the solution provided by you worked but it’s not mentioned in the hint. Instead, hint is directing towards “ecdsa_curve” which does not need to be changed.