I am unable to get this right even after checking the hint given to answer the question.
The key algorithm used by tls-cert-request is ECDSA but the private-key is of type RSA is the hint. I changed the key algorithm to RSA but it still doesn’t work. I looked up for answers online on the terraform website too but I am unable to understand what needs to be done to make this work.
Can someone help me here?
but the most important is that you have not to forget to plan and apply by using those commands and it will work fine as shown.
terraform plan
terraform apply
iac-server $ terraform plan
Error: Invalid function argument
on main.tf line 13, in resource "tls_cert_request" "csr":
13: private_key_pem = file("/tmp/.pki/private_key.pem")
Invalid value for "path" parameter: no file exists at
/tmp/.pki/private_key.pem; this function works only with files that are
distributed as part of the configuration source code, so if this file will be
created by a resource in this configuration you must instead obtain this
result from an attribute of that resource.
iac-server $
Error: Invalid Configuration for Read-Only Attribute
on main.tf line 11, in resource “tls_cert_request” “csr”:
11: key_algorithm = “RSA”
Cannot set value for this attribute as the provider has marked it as
read-only. Remove the configuration line setting the value.
Refer to the provider documentation or contact the provider developers for
additional information about configurable and read-only attributes that are
supported.
It needs to be added to the main.tf but you need to replace the “” after copy-paste.
Unfortunately, it throws a new error now.
Warning: Argument is deprecated
on main.tf line 12, in resource "tls_cert_request" "csr":
12: key_algorithm = "RSA"
This is now ignored, as the key algorithm is inferred from the
`private_key_pem`.
Error: Resource instance managed by newer provider version
The current state of tls_private_key.private_key was created by a newer
provider version than is currently selected. Upgrade the tls provider to work
with this state.
There are two errors with the validation - when you fix the first, then the second appears
Error: Unsupported argument - change dsa_bits to rsa_bits
Error: Invalid Configuration for Read-Only Attribute - Terraform gives you this error when you try to provide a value for an attribute that is declared read-only by the provider. That’s not just for this provider, but any provider. Read-only attributes cannot be set in configuration, only referred to. Correct fix is to remove the attribute, then it will validate.
Once the CSR resource has been applied, other resources can read the value of key_algorithm to discover what algorithm was chosen by the provider.
Note that changing the provider version to one that has a read/write version of the attribute isn’t what the lab is asking you to do
I really did not understand your explanation. Can you Please elaborate and tell how we can get rid of the Error: Invalid Configuration for Read-Only Attribute error.
You get rid of the error by removing the attribute entirely!
With the version 4 of this provider (which is the version used by the lab), it is not valid to give that attribute a value. The provider chooses it automatically. It is not writable, just like a read only file is not writable. Assigning a value in the configuration file is writing.