hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Bug]: aws_iam_service_specific_credential password git credentials #38954

Open sergio1986bcn opened 3 weeks ago

sergio1986bcn commented 3 weeks ago

Terraform Core Version

1.9.5

AWS Provider Version

5.63.1,5.62.0

Affected Resource(s)

aws_iam_service_specific_credential

Expected Behavior

The password generated by the aws_iam_service_specific_credential resource should be valid and not contain unexpected special characters, such as the # character

The password should be directly usable for authentication to AWS CodeCommit, without the need to remove additional characters or make modifications.

Actual Behavior

Instead of generating a password that can be used directly without modification, the aws_iam_service_specific_credential resource is generating a password that includes a trailing # character and affects authentication to AWS CodeCommit.

image

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = " 5.63.1"
    }
  }
}

provider "aws" {
  region  = "eu-west-1"
}

resource "aws_iam_user" "codecommit" {
  name = "git-codecommit"
}

resource "aws_iam_service_specific_credential" "codecommit" {
  service_name = "codecommit.amazonaws.com"
  user_name    = aws_iam_user.codecommit.name

  depends_on = [aws_iam_user.codecommit]
}

output "test" {
  sensitive = true
  value = aws_iam_service_specific_credential.codecommit.service_password
}

Steps to Reproduce

terraform init terraform apply terraform output -raw test

Debug Output

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 3 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 3 weeks ago

Hey @sergio1986bcn 👋 Thank you for taking the time to raise this! I took a look at the resource schema, and it appears the resource is returning exactly what the API returns.

I noticed that you're using the -raw flag for terraform output. Is it possible that what you're seeing is a # being printed due to there not being a newline at the end of the returned string? For example, with the following configuration:

resource "random_pet" "test" {}

output "test" {
  value = random_pet.test.id
}

I have the following results:

$ terraform output
test = "upward-flounder"

$ terraform output -raw test
upward-flounder%

$ terraform output test
"upward-flounder"

$ terraform output -json test | jq -r '.'
upward-flounder