AWS named provider "doesn't support resource: terraform_remote_state"

965 views
Skip to first unread message

Nicholas Avenell

unread,
Apr 28, 2016, 6:15:48 AM4/28/16
to Terraform
I'm using terraform to orchestrate stuff across a few aws accounts, so pretty much everything is going in with a specific provider, and this has worked beautifully right up until trying to put the state file in a remote bucket.

If I leave it to default, it works, but I really would prefer to specify providers to avoid future things being accidentally put in the wrong account. 

```
provider "aws" {
    alias = "infrastructure-account"
    profile = "${var.infra_profile_name}"
    region = "eu-west-1"
}

provider "aws" {
    alias = "target"
    profile = "${var.target_profile_name}"
    region = "eu-west-1"
}
```

```
resource "terraform_remote_state" "bucket" {
    backend = "s3"
    provider = "aws.infrastructure-account"
    config {
        bucket = "els-terraform-state"
        key = "${template_file.state_key.rendered}"
        region = "eu-west-1"
    }
}
```

```
(saml)vagrant@vagrant-ubuntu-trusty-64 (master *) /vagrant/Nicholas/Aegis2: terraform -v
Terraform v0.6.15

(saml)vagrant@vagrant-ubuntu-trusty-64 (master *) /vagrant/Nicholas/Aegis2: terraform plan -var-file=evpc.tfvars
There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Errors:

  * terraform_remote_state.bucket: Provider doesn't support resource: terraform_remote_state
```


Martin Atkins

unread,
May 12, 2016, 9:02:40 PM5/12/16
to Terraform
Setting provider to a string starting with "aws." only makes sense for resources from the AWS provider, whose names will start with "aws_".

With the configuration you posted, Terraform is trying to find a resource called "terraform_remote_state" inside the "aws" provider, when it should instead be looking for it in the "terraform" provider.

I thnk what you're trying to do here is control which credentials are used to fetch the state from S3. Unfortunately, the S3 remote state backend is a distinct concept from the AWS provider, and so it gets its configuration only from the config block, entirely ignoring the AWS provider configuration. I think you can get the effect you are looking for here by removing the provider argument from the remote state and then setting the profile directly within the backend config:

resource "terraform_remote_state" "bucket" {
    backend = "s3"
    config {
        bucket = "els-terraform-state"
        key = "${template_file.state_key.rendered}"
        region = "eu-west-1"
        profile = "${var.infra_profile_name}"

Nicholas Avenell

unread,
May 13, 2016, 4:13:05 AM5/13/16
to Terraform
That is what I'm attempting to do, thanks for the pointer, I'll give that a try
Reply all
Reply to author
Forward
0 new messages