Answers: <p>I think you could achieve something similar by first running Terraform against your RDS resources, and then running Terraform again on all resources.</p>
  
  <p>On your first pass, you can use <code>-target</code> option to target only a subset of the resources. (ie. RDS resources). </p>
  
  <p>Be aware that using this option is not recommended in Terraform docs. If I were you, I would use it for time being and change it as soon as one of these issues below is solved:
  <a href="https://github.com/hashicorp/terraform/issues/10462" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/10462</a>
  <a href="https://github.com/hashicorp/terraform/issues/2430" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/2430</a>
  <a href="https://github.com/hashicorp/terraform/issues/4149" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/4149</a></p>
  
  <p>For details on how to use <code>-target</code> and its caveats, see: <a href="https://www.terraform.io/docs/commands/plan.html#resource-targeting" rel="nofollow noreferrer">https://www.terraform.io/docs/commands/plan.html#resource-targeting</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2018-07-15T19:03:58.837Z
Answers: 2018-07-15T19:03:58.837Z
Answers: Yekta Leblebici
Body: <p>I have a Terraform project which uses the MySQL provider.  Because of the way Terraform works, the MySQL provider will fail to load correctly because the AWS_RDS instance doesn't exist.  Is there a way for me to delay or split my project so that the MySQL provider doesn't load during the main "apply"?</p>
  
  <p>I've examined workspaces, and I see that you can use a count to trigger a resource to load or not load based off of the workspace name.  But that didn't work anyway I thought.</p>
  
  <p>I've also seen this issue mentioned on the Hashicorp GitHub, but on one seems to be offering a workaround</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Here is a snippet of my data-storage configuration thus far:</p>
  
  <pre><code>resource "aws_db_subnet_group" "default" {
    name       = "${var.database_subnet_group_name}"
    subnet_ids = ["${var.database_subnets}"]
  
    tags {
      Name = "${var.database_subnet_group_name}"
    }
  }
  
  resource "aws_rds_cluster_instance" "cluster_instances" {
    count              = 1
    identifier         = "app-aurora-cluster-${count.index}"
    cluster_identifier = "${aws_rds_cluster.some_cluster.id}"
    instance_class     = "db.t2.medium"
    db_subnet_group_name = "${var.database_subnet_group_name}"
    publicly_accessible = true
  }
  
  resource "aws_rds_cluster" "some_cluster" {
    cluster_identifier = "app-aurora-cluster"
    availability_zones = ["${var.database_azs}"]
    database_name      = "${var.database_name}"
    db_subnet_group_name = "${var.database_subnet_group_name}"
    master_username    = "auroradmin"
    master_password    = "%XwPn}gU6sX&lt;y8Wx"
    skip_final_snapshot =  true
    vpc_security_group_ids = ["${var.database_security_groups}"]
  }
  /*
  # This has to be commented out during the first pass
  # because Terraform will try to connect to the 
  # MySQL Aurora server to refresh the state even 
  # though it currently doesn't exist.
  # Configure the MySQL provider
  provider "mysql" {
  
    endpoint = "${aws_rds_cluster.some_cluster.endpoint}"
    username = "auroradmin"
    password = "%XwPn}gU6sX&lt;y8Wx"
  }
  </code></pre>
  
Comments: CC BY-SA 3.0
Comments: 2018-02-14T02:55:01.130Z
Comments: Maybe show your (related) terraform configuration(s)?
Comments: Dan Cornilescu
Comments: CC BY-SA 3.0
Comments: 2018-02-14T02:58:06.840Z
Comments: @DanCornilescu I'm a Terra-Scrub right now, but I've edited my post with what I believe you mean as my configuration.  Basically, I create the RDS stuff first, then uncomment the mysql stuff, and run my "apply" again.  Clearly a suboptimal and unintelligent way to go about things.
Comments: Black Dynamite
Comments: CC BY-SA 3.0
Comments: 2018-02-14T03:42:56.877Z
Comments: Wouldn't you need the "mysql" provider to reference the cluster instance instead of the cluster? (sorry, my Q may be dumb, I only read a bit about terraform)
Comments: Dan Cornilescu
Comments: CC BY-SA 3.0
Comments: 2018-02-14T03:44:04.863Z
Comments: I was looking at this example: https://www.terraform.io/docs/providers/mysql/index.html
Comments: Dan Cornilescu
Tags: <terraform><mysql><terraform-module><terraform-workspace>
Title: Terraform: Delay the MySQL Provider
UserDisplayName: Black Dynamite
ThreadText: # Terraform: Delay the MySQL Provider
  
  (Asked by: username_0 on 2018-02-14)
  
  I have a Terraform project which uses the MySQL provider. Because of the way Terraform works, the MySQL provider will fail to load correctly because the AWS\_RDS instance doesn't exist. Is there a way for me to delay or split my project so that the MySQL provider doesn't load during the main "apply"?
  
  I've examined workspaces, and I see that you can use a count to trigger a resource to load or not load based off of the workspace name. But that didn't work anyway I thought.
  
  I've also seen this issue mentioned on the Hashicorp GitHub, but on one seems to be offering a workaround
  
  Any help is greatly appreciated.
  
  Here is a snippet of my data-storage configuration thus far:
  
  ```
  resource "aws_db_subnet_group" "default" {
    name       = "${var.database_subnet_group_name}"
    subnet_ids = ["${var.database_subnets}"]
  
    tags {
      Name = "${var.database_subnet_group_name}"
    }
  }
  
  resource "aws_rds_cluster_instance" "cluster_instances" {
    count              = 1
    identifier         = "app-aurora-cluster-${count.index}"
    cluster_identifier = "${aws_rds_cluster.some_cluster.id}"
    instance_class     = "db.t2.medium"
    db_subnet_group_name = "${var.database_subnet_group_name}"
    publicly_accessible = true
  }
  
  resource "aws_rds_cluster" "some_cluster" {
    cluster_identifier = "app-aurora-cluster"
    availability_zones = ["${var.database_azs}"]
    database_name      = "${var.database_name}"
    db_subnet_group_name = "${var.database_subnet_group_name}"
    master_username    = "auroradmin"
    master_password    = "%XwPn}gU6sX<y8Wx"
    skip_final_snapshot =  true
    vpc_security_group_ids = ["${var.database_security_groups}"]
  }
  /*
  # This has to be commented out during the first pass
  # because Terraform will try to connect to the 
  # MySQL Aurora server to refresh the state even 
  # though it currently doesn't exist.
  # Configure the MySQL provider
  provider "mysql" {
  
    endpoint = "${aws_rds_cluster.some_cluster.endpoint}"
    username = "auroradmin"
    password = "%XwPn}gU6sX<y8Wx"
  }
  
  ```
  
  **Tags:** terraform, mysql, terraform-module, terraform-workspace
  
  > **Comments:**
  > **username_1**: Maybe show your (related) terraform configuration(s)?  
  > **username_0**: @username_1 I'm a Terra-Scrub right now, but I've edited my post with what I believe you mean as my configuration.  Basically, I create the RDS stuff first, then uncomment the mysql stuff, and run my "apply" again.  Clearly a suboptimal and unintelligent way to go about things.  
  > **username_1**: Wouldn't you need the "mysql" provider to reference the cluster instance instead of the cluster? (sorry, my Q may be dumb, I only read a bit about terraform)  
  > **username_1**: I was looking at this example: https://www.terraform.io/docs/providers/mysql/index.html  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-07-15. Score: 1
  
  I think you could achieve something similar by first running Terraform against your RDS resources, and then running Terraform again on all resources.
  
  On your first pass, you can use `-target` option to target only a subset of the resources. (ie. RDS resources).
  
  Be aware that using this option is not recommended in Terraform docs. If I were you, I would use it for time being and change it as soon as one of these issues below is solved:
  <https://github.com/hashicorp/terraform/issues/10462>
  <https://github.com/hashicorp/terraform/issues/2430>
  <https://github.com/hashicorp/terraform/issues/4149>
  
  For details on how to use `-target` and its caveats, see: <https://www.terraform.io/docs/commands/plan.html#resource-targeting>
  
  
  ---
  
  