DevOps-Journey-Using-Azure-DevOps icon indicating copy to clipboard operation
DevOps-Journey-Using-Azure-DevOps copied to clipboard

Getting Error While Running the lab2pipeline.yaml pipeline in Validate stage

Open SRP07 opened this issue 2 years ago • 3 comments

Hi Thomas,

I was going through your "DevOps-Journey-Using-Azure-DevOps" tutorial and trying to learn and while running the lab2pipeline.yaml pipeline I am getting an error which I am not able to understand and not able to move ahead.

Here, is what I have done so far.

  1. Have installed all pre-requisites.
  2. Create a new RG and storage account by following the steps mentioned by you in Initial setup.
  3. Now in second steps i.e. in Setup Azure DevOps Pipeline. I cloned your code in my ADO repo and updated the variables in pipeline yml file with my RG name, storage account name.
  4. Also updated the RG and storage account name in providers.tf of the main code and also updated location in all the variables files of modules to "East US 2" to match my RG location.
  5. Now when I try to run the pipeline it fail with below error in "init" task -

##[error]Error: There was an error when attempting to execute the process '/opt/hostedtoolcache/terraform/1.2.6/x64/terraform'. This may indicate the process failed to start. Error: spawn /opt/hostedtoolcache/terraform/1.2.6/x64/terraform ENOENT

Attaching screenshot of the build along with its log for reference. TF Init pipeline failure

1_validate (1).txt

If possible could you please let me know what am I missing as I just started learning about TF with ADO I am unsure of couple of things?

I also tried running the TF commands in VS code after making the changes in files and after I run the Terraform init command it is asking me for a blob key to enter. I am not aware where can I find this key, I tried searching on internet and went to my storage account and then to its access keys section there I saw Key1 and key2 and then tried copy key1 in my VS code but it failed with error, so I am not sure again where I am missing here.

here is the error along with its image attached.

Error: Failed to get existing workspaces: containers.Client#ListBlobs: Failure responding to request: StatusCode=400 -- Original Error: autorestst/azure: Service returned an error. Status=400 Code="InvalidResourceName" Message="The specifed resource name contains invalid characters.\nReqstuestId:46890cce-f01e-0065-5f03-b0948c000000\nTime:2022-08-14T17:32:23.3160187Z"

image

SRP07 avatar Aug 14 '22 17:08 SRP07

Hi,

Thank you for raising this - can you confirm your folder directory is correct in initial Azure Devops? Here is an example of your error I blogged: https://thomasthornton.cloud/2022/01/24/error-spawn-terraform-enoent-when-running-terraform-in-azure-devops-pipeline/

You may have to modify the workingDirectory within your ADO pipeline

=======

Regarding your second query, did you modify this reference?

terraform { backend "azurerm" { resource_group_name = "devops-journey-rg" storage_account_name = "devopsjourneyazuredevops" container_name = "terraform.tfstate" } }`

& yes it is the storage account key as you referenced. Please note in your screenshot you provided storage account key - I would revoke that asap

thomast1906 avatar Aug 15 '22 08:08 thomast1906

Hi,

I was able to resolve the pipeline error by referring your comment in your block for similar issue reported by Jason Thornbrugh. After that I was able to move ahead but got stuck again in Apply Stage with below -

Had created new RG and thus had to update modules files with my RG name but it seems in modules code I think we are trying to create another RG. May be I'll have to comment that code or let it create new RG with new name. I am new to it may be I am making couple mistakes while performing this exercise but I am leaning new stuff while resolving it. Thanks.

Yes, I revoked the key as suggested by you for my storage account.

Error: A resource with the ID "/subscriptions/1a2b9a36-bcef-4e69-95b4-b62faaf9ae2d/resourceGroups/MSDN-RG-SURAJ" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_resource_group" for more information. │ │ with module.acr.azurerm_resource_group.acr_resource_group, │ on modules/acr/acr.tf line 1, in resource "azurerm_resource_group" "acr_resource_group": │ 1: resource "azurerm_resource_group" "acr_resource_group" { │ ╵ ╷ │ Error: A resource with the ID "/subscriptions/1a2b9a36-bcef-4e69-95b4-b62faaf9ae2d/resourceGroups/MSDN-RG-SURAJ" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_resource_group" for more information. │ │ with module.aks.azurerm_resource_group.kubernetes_resource_group, │ on modules/aks/aks.tf line 1, in resource "azurerm_resource_group" "kubernetes_resource_group": │ 1: resource "azurerm_resource_group" "kubernetes_resource_group" {

SRP07 avatar Aug 15 '22 08:08 SRP07

Awesome, glad you hear it resolved!

Regarding your two latest errors, looks like state conflict - where they created elsewhere in a different state file? I'd probably remove the RGs and allow for a fresh terraform apply

thomast1906 avatar Aug 15 '22 09:08 thomast1906