Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try() to generate output.ses_smtp_password_v4 #32

Closed

Conversation

rsrchboy
Copy link
Contributor

In module upgrades, I'm seeing errors like this:

Error: Invalid function argument

on .terraform/modules/user/outputs.tf line 29, in output "ses_smtp_password_v4":
29:   value       = join("", aws_iam_access_key.default.*.ses_smtp_password_v4)
    |----------------
    | aws_iam_access_key.default is tuple with 1 element

Invalid value for "lists" parameter: element 0 is null; cannot concatenate
null values.

This change wraps the join() with a try(..., null), causing null
to be returned as a fallback on error.

In module upgrades, I'm seeing errors like this:

    Error: Invalid function argument

    on .terraform/modules/user/outputs.tf line 29, in output "ses_smtp_password_v4":
    29:   value       = join("", aws_iam_access_key.default.*.ses_smtp_password_v4)
        |----------------
        | aws_iam_access_key.default is tuple with 1 element

    Invalid value for "lists" parameter: element 0 is null; cannot concatenate
    null values.

This change wraps the `join()` with a `try(..., null)`, causing `null`
to be returned as a fallback on error.
@rsrchboy rsrchboy requested a review from a team as a code owner August 21, 2020 15:19
@rsrchboy rsrchboy requested review from jhosteny and SweetOps and removed request for a team August 21, 2020 15:19
@SweetOps
Copy link
Contributor

It is very weird... all outputs in this module use construction join("", something), but you've got error only in one place. I suppose that need to bump version of aws provider and it'll fix issue permamently

https://github.com/cloudposse/terraform-aws-iam-system-user/blob/master/versions.tf#L5

@aknysh aknysh mentioned this pull request Sep 2, 2020
@aknysh aknysh closed this in #34 Sep 2, 2020
@kristjankullerkann
Copy link

I seem to be hitting this very same issue.
In more details:

  • I am using cloudposse/terraform-aws-s3-bucket which has a dependency to cloudposse/terraform-aws-iam-s3-user which has dependency to this module.
  • I have something like this in my provider configuration (so it should be quite new):
provider "aws" {
  version = "~> 3.7.0"
  region = var.region
  profile = var.profile
  shared_credentials_file = var.shared_credentials_file
}
  • terraform is 0.13.3
  • interesting to note that this happens only on upgrade, because creating a new s3 bucket doesn't introduce this error.

@kristjankullerkann
Copy link

I think I have managed to identify the issue and resolve it.

In the older module, we can find from state file something like:

{
  "module": "module.s3_bucket.module.s3_user.module.s3_user",
  "mode": "managed",
  "type": "aws_iam_access_key",
  "name": "default",
  "provider": "provider[\"registry.terraform.io/-/aws\"]",
  "instances": [
    {
      "index_key": 0,
      "schema_version": 0,
      "attributes_flat": {
        "id": "someid",
        "secret": "somesecret",
        "ses_smtp_password": "somesecret",
        "status": "Active",
        "user": "user"
      }
    }
  ]
}

In the newer module, we can find something like:

{
  "module": "module.s3_bucket.module.s3_user.module.s3_user",
  "mode": "managed",
  "type": "aws_iam_access_key",
  "name": "default",
  "provider": "provider[\"registry.terraform.io/-/aws\"]",
  "instances": [
    {
      "index_key": 0,
      "schema_version": 0,
      "attributes_flat": {
        "id": "someid",
        "secret": "somesecret",
        "ses_smtp_password_v4": "somesecret",
        "status": "Active",
        "user": "user"
      }
    }
  ]
}

As you can see the key named ses_smtp_password has changed to ses_smtp_password_v4.

After modifying key name, I managed to successfully upgrade the module and its state.

Workflow is as follows:

  1. pull the state with terraform state pull > state.out.
  2. modify state.out file as described above.
  3. push state with terraform state push -force state.out.
  4. upgrade module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants