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

Terraform fails to import a CloudTrail with 'Organization Trail' set to true #15553

Closed
dev-e opened this issue Oct 7, 2020 · 3 comments · Fixed by #30758
Closed

Terraform fails to import a CloudTrail with 'Organization Trail' set to true #15553

dev-e opened this issue Oct 7, 2020 · 3 comments · Fixed by #30758
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudtrail Issues and PRs that pertain to the cloudtrail service.
Milestone

Comments

@dev-e
Copy link

dev-e commented Oct 7, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.13.4
+ provider registry.terraform.io/hashicorp/aws v3.9.0

Affected Resource(s)

  • aws_cloudtrail

Terraform Configuration Files

provider "aws" {
  alias   = "va"
  region  = "us-east-1"
  version = ">= 3.9.0"
}

resource "aws_cloudtrail" "events" {
  provider       = aws.va
  is_organization_trail = true
  name           = "events"
  s3_bucket_name = "events"
}

Expected Behavior

Trail imported

Actual Behavior

$ terraform state import aws_cloudtrail.events events                                    
aws_cloudtrail.events: Importing from ID "events"...
aws_cloudtrail.events: Import prepared!
  Prepared aws_cloudtrail for import
aws_cloudtrail.events: Refreshing state... [id=events]

Error: Cannot import non-existent remote object

While attempting to import an existing object to
aws_cloudtrail.events, the provider detected that no object exists
with the given id. Only pre-existing objects can be imported; check that the
id is correct and that it is associated with the provider's configured region
or endpoint, or use "terraform apply" to create a new remote object for this
resource.

Releasing state lock. This may take a few moments...

Steps to Reproduce

  1. manually create the CloudTrail trail with name trail-organizations
  2. set Apply trail to my organization to yes
  3. select/create an S3 bucket
  4. try to import the resource

Important Factoids

A trail with "IsOrganizationTrail": true cannot be described by the name, only by the arn. However, import relies on Name field

$ aws cloudtrail describe-trails --trail-name-list='["events"]' --region=us-east-1                                                
{
    "trailList": []
}
$ aws cloudtrail describe-trails --trail-name-list='["arn:aws:cloudtrail:us-east-1:<AWS_ACCOUNT_ID>:trail/events"]' --region=us-east-1
{
    "trailList": [
        {
            "Name": "events",
            "S3BucketName": "events",
            "IncludeGlobalServiceEvents": true,
            "IsMultiRegionTrail": true,
            "HomeRegion": "us-east-1",
            "TrailARN": "arn:aws:cloudtrail:us-east-1:<AWS_ACCOUNT_ID>:trail/events",
            "LogFileValidationEnabled": true,
            "HasCustomEventSelectors": false,
            "HasInsightSelectors": false,
            "IsOrganizationTrail": true
        }
    ]
}

References

@ghost ghost added the service/cloudtrail Issues and PRs that pertain to the cloudtrail service. label Oct 7, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 7, 2020
@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 16, 2021
@faleon
Copy link

faleon commented Jun 8, 2023

This import function also fails for non-Organization Trails aka regular trails.

PS C:\Users\faleon\Documents\jfrog-pipelines\terraform\aws\all-accounts> terraform import -var=account_ou="ou" aws_cloudtrail.cloudtrail aws-controltower-BaselineCloudTrail
Acquiring state lock. This may take a few moments...
data.aws_vpcs.vpcs: Reading...
data.aws_iam_policy_document.logging_policy_doc[0]: Reading...
data.aws_iam_policy_document.logging_kms_key_policy: Reading...
data.aws_iam_policy_document.logging_trust[0]: Reading...
data.aws_iam_policy_document.logging_policy_doc[0]: Read complete after 0s [id=2351691002]
data.aws_iam_policy_document.logging_trust[0]: Read complete after 0s [id=4054724619]
data.aws_iam_policy_document.logging_kms_key_policy: Read complete after 0s [id=704465212]
data.aws_vpcs.vpcs: Read complete after 0s [id=us-east-1]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Releasing state lock. This may take a few moments...
PS C:\Users\faleon\Documents\jfrog-pipelines\terraform\aws\all-accounts> terraform import -var=account_ou="ou" aws_cloudtrail.cloudtrail aws-controltower-BaselineCloudTrail
Acquiring state lock. This may take a few moments...
data.aws_vpcs.vpcs: Reading...
data.aws_iam_policy_document.logging_policy_doc[0]: Reading...
data.aws_iam_policy_document.logging_trust[0]: Reading...
data.aws_iam_policy_document.logging_policy_doc[0]: Read complete after 0s [id=2351691002]
data.aws_iam_policy_document.logging_trust[0]: Read complete after 0s [id=4054724619]
data.aws_iam_policy_document.logging_kms_key_policy: Reading...
data.aws_iam_policy_document.logging_kms_key_policy: Read complete after 0s [id=704465212]
data.aws_vpcs.vpcs: Read complete after 1s [id=us-east-1]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Releasing state lock. This may take a few moments...
PS C:\Users\faleon\Documents\jfrog-pipelines\terraform\aws\all-accounts>

Terraform doesn't seem to import anything for CloudTrail.

@github-actions github-actions bot added this to the v5.25.0 milestone Nov 6, 2023
Copy link

This functionality has been released in v5.25.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudtrail Issues and PRs that pertain to the cloudtrail service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants