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

schema: Computed Value Hints for Downstream Validation #61

Open
radeksimko opened this issue Feb 7, 2016 · 1 comment
Open

schema: Computed Value Hints for Downstream Validation #61

radeksimko opened this issue Feb 7, 2016 · 1 comment
Labels
enhancement New feature or request upstream-protocol Requires change of protocol specification, i.e. can't be done under the current protocol

Comments

@radeksimko
Copy link
Member

Consider the following example:

resource "aws_cloudtrail" "foobar" {
    name = "tf-trail-foobar"
    s3_bucket_name = "${aws_s3_bucket.foo.arn}" # ARN instead of name
    s3_key_prefix = "/prefix"
    include_global_service_events = false
}

resource "aws_s3_bucket" "foo" {
    bucket = "tf-yada-test-trail"
    force_destroy = true
    policy = <<POLICY
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AWSCloudTrailAclCheck",
            "Effect": "Allow",
            "Principal": {
              "Service": "cloudtrail.amazonaws.com"
            },
            "Action": "s3:GetBucketAcl",
            "Resource": "arn:aws:s3:::tf-yada-test-trail"
        },
        {
            "Sid": "AWSCloudTrailWrite",
            "Effect": "Allow",
            "Principal": {
              "Service": "cloudtrail.amazonaws.com"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::tf-yada-test-trail/*",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                }
            }
        }
    ]
}
POLICY
}

Even though it is obvious that ARN cannot be used in a parameter where we expect raw name, terraform isn't able to check this, because ARN is computed (put away the fact we don't have ValidateFunc on s3_bucket_name for the moment). Instead API error is returned at a point when S3 bucket has been already created.

Error applying plan:

1 error(s) occurred:

* aws_cloudtrail.foobar: InvalidS3BucketNameException: Bucket name should not contain ':': arn:aws:s3:::tf-yada-test-trail

Maybe this could be done by introducing something like example_value for each Computed field and output against which we could then validate?

@bigkraig
Copy link

bigkraig commented Mar 3, 2016

👍 ran into this one today.

We have a module that generates standard names for all of our AWS resources and this can generate names with uppercase letters. AWS doesn't mind if there are uppercase letters but Terraform does and this creates a Unable to find errors.

Look at this apply

Remote state configured and pulled.
aws_db_parameter_group.default: Creating...
  arn:         "" => "<computed>"
  description: "" => "parameter group for generate-name database"
  family:      "" => "oracle-ee-11.2"
  name:        "" => "TEST-ENV-twb-oracle"
Error applying plan:

1 error(s) occurred:

* aws_db_parameter_group.default: Unable to find Parameter Group: []*rds.DBParameterGroup{{
  DBParameterGroupFamily: "oracle-ee-11.2",
  DBParameterGroupName: "test-env-twb-oracle",
  Description: "parameter group for generate-name database"
}}

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

@radeksimko radeksimko changed the title schema: ValidateFunc should also check Computed values schema: ValidateFunc should also check interpolated values Apr 23, 2017
@hashibot hashibot transferred this issue from hashicorp/terraform Sep 26, 2019
@hashibot hashibot added the enhancement New feature or request label Oct 2, 2019
@paddycarver paddycarver added the upstream-protocol Requires change of protocol specification, i.e. can't be done under the current protocol label Sep 15, 2020
@bflad bflad changed the title schema: ValidateFunc should also check interpolated values schema: Computed Value Hints for Downstream Validation Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request upstream-protocol Requires change of protocol specification, i.e. can't be done under the current protocol
Projects
None yet
Development

No branches or pull requests

4 participants