This is what it would look like in the state file if it is created from the scratch by terraform:
{
"module": "module.rds",
"mode": "managed",
"type": "aws_cloudwatch_log_subscription_filter",
"name": "rds_logs_delivery",
"each": "map",
"provider": "provider.aws",
"instances": [
{
"index_key": "prod-service-master.audit",
"schema_version": 0,
"attributes": {
"destination_arn": "arn:aws:firehose:us-east-5:9999999999:deliverystream/prod-rds-logs",
"distribution": "ByLogStream",
"filter_pattern": "",
"id": "cwlsf-9999999999",
"log_group_name": "/aws/rds/instance/prod-service-master/audit",
"name": "rds-logs-delivery-prod-service-master",
"role_arn": "arn:aws:iam::9999999999:role/cloudwatch-logs-to-kinesis"
},
"private": "abcdefg",
"depends_on": [
"data.aws_caller_identity.current",
"data.aws_partition.current",
"data.terraform_remote_state.kinesis_delivery_stream"
]
},
For some reasons I need to import this into another tf state file. So I ran this command:
terraform import module.rds.aws_cloudwatch_log_subscription_filter.rds_logs_delivery["prod-service-reports.audit"] rds-logs-delivery-prod-service-master
I got this error:
Error: Index value required
on <import-address> line 1:
1: module.rds.aws_cloudwatch_log_subscription_filter.rds_logs_delivery[prod-service-reports.audit]
Index brackets must contain either a literal number or a literal string.
How can I fix it? I have tried
but I still get the same error.
You need to escape the quotes. As in,
terraform import module.rds.aws_cloudwatch_log_subscription_filter.rds_logs_delivery[\"prod-service-reports.audit\"] rds-logs-delivery-prod-service-master
As suggested by @JamesK in this answer above is only the solution if you are using Linux or more specifically bash or Git Bash under Windows.
The solution for PowerShell is the following:
terraform import resource[\`"prod-service-reports.audit\`"] ...
Thanks to the answer here :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With