Closed lsanchez-v closed 7 months ago
Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:
The ticket CLOUDP-229736 was created for internal tracking.
Hi @lsanchez-v 👋 Thanks for opening the issue! Could you also provide the piece of code in your pipeline that runs the TF provider and where you defined your vars? This would help us reproduce the issue. Out of curiosity, have you tried to run the same TF conf outside of the pipeline? did you get the same errors? Thanks!
Hi @andreaangiolillo
Yes sure, here is the part of the pipeline that runs that TF code:
.update_terraform_version: &update_terraform_version
- git clone --depth=1 https://github.com/tfutils/tfenv.git tfenv
- tfenv/bin/tfenv install 1.6.6
- tfenv/bin/tfenv use 1.6.6
.export_mongodb_atlas_credentials: &export_mongodb_atlas_credentials
- export MONGODB_ATLAS_PUBLIC_KEY=$MONGODB_ATLAS_LIVE_PUBLIC_KEY
- export MONGODB_ATLAS_PRIVATE_KEY=$MONGODB_ATLAS_LIVE_PRIVATE_KEY
.validate_ci_script: &validate_ci_script
- cd live_account/mongodb_atlas/per_env
- rm -rf .terraform
- terraform init -input=false -backend-config=environments/ci/terraform.backend -upgrade
- terraform validate
.plan_ci_script: &plan_ci_script
- terraform plan -input=false -var-file=environments/ci/terraform.tfvars -out $PLAN
- terraform show --json $PLAN | jq -r $REPORT_FILTER > $PLAN_JSON
- cat $PLAN_JSON
plan_ci:
stage: plan
only:
changes:
- live_account/mongodb_atlas/per_env/**/*
refs:
- merge_requests
except:
- master
tags:
- dev
script:
- *update_terraform_version
- *validate_ci_script
- *export_mongodb_atlas_credentials
- *plan_ci_script
The variables are defined in a .tfvars file.
Indeed running the TF code from local works, it only fails from the pipeline.
Thanks!
@lsanchez-v thanks for providing the script. If running TF code from local works, it might be worth it to understand if the pipeline is adding/removing some value compared to when you are directly calling the script. Also: can you confirm that you are actually using the provider version 1.15.1 when using the pipeline?
@marcosuma Here is the output of the pipeline when installing the TF providers:
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 5.0"...
- Finding mongodb/mongodbatlas versions matching "~> 1.15"...
- Installing hashicorp/aws v5.36.0...
- Installed hashicorp/aws v5.36.0 (self-signed, key ID 34365D9472D7468F)
- Installing mongodb/mongodbatlas v1.15.1...
- Installed mongodb/mongodbatlas v1.15.1 (signed by a HashiCorp partner, key ID 2A32ED1F3AD25ABF)
Another curious thing is that we are deploying another Atlas module using the same provider version from that same pipeline, and that one works correctly, so it seems to me that it could be maybe related to the resources being deployed. Here is the TF code of the other module:
locals {
mongodbatlas_privatelink_endpoint_attrs_to_export = ["endpoint_service_name", "project_id", "private_link_id"]
}
resource "mongodbatlas_network_container" "mongo_atlas" {
project_id = var.mongodb_atlas_project_id
atlas_cidr_block = var.mongodb_atlas_cidr_block
provider_name = "AWS"
region_name = var.provider_region_name
}
#
# Private link
#
resource "mongodbatlas_privatelink_endpoint" "mongo_pl" {
project_id = var.mongodb_atlas_project_id
provider_name = "AWS"
region = var.aws_region_name
depends_on = [mongodbatlas_network_container.mongo_atlas]
}
resource "aws_ssm_parameter" "privatelink_endpoint_data" {
for_each = {
for k, v in mongodbatlas_privatelink_endpoint.mongo_pl : k => v
if contains(local.mongodbatlas_privatelink_endpoint_attrs_to_export, k)
}
name = "/mongodb_atlas/private_link/${each.key}"
description = "MongoDb Atlas Private Link Endpoint Attr ${each.key}"
type = "String"
value = each.value
}
The pipeline structure for this module is exactly the same as the other one.
Indeed running the TF code from local works, it only fails from the pipeline.
Given this resolving issue, suggest escalating this item to GitLab repo. Feel free to open new issue in case you need else related to Terraform MongoDB Atlas Provider
Is there an existing issue for this?
Provider Version
v1.15.1
Terraform Version
v1.6.6
Terraform Edition
Terraform Open Source (OSS)
Current Behavior
When running Terraform from GitLab pipelines, I'm getting this provider related errors:
Steps To Reproduce
terraform plan
Logs
No response
Code of Conduct