hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io
Other
42.76k stars 9.56k forks source link

creating Neptune Cluster: InvalidDBClusterStateFault #32430

Closed afaqueahmad closed 1 year ago

afaqueahmad commented 1 year ago

Terraform Version

Terraform v1.3.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.46.0

Terraform Configuration Files

provider "aws" {
  alias  = "primary"
  region = "us-east-2"
}

provider "aws" {
  alias  = "secondary"
  region = "us-east-1"
}

resource "aws_neptune_global_cluster" "example" {
  global_cluster_identifier = "global-test"
  engine                    = "neptune"
  engine_version            = "1.2.0.0"
}

resource "aws_neptune_cluster" "primary" {
  provider                  = aws.primary
  engine                    = aws_neptune_global_cluster.example.engine
  engine_version            = aws_neptune_global_cluster.example.engine_version
  cluster_identifier        = "test-primary-cluster"
  global_cluster_identifier = aws_neptune_global_cluster.example.id
  neptune_subnet_group_name = "default"
}

resource "aws_neptune_cluster_instance" "primary" {
  provider                  = aws.primary
  engine                    = aws_neptune_global_cluster.example.engine
  engine_version            = aws_neptune_global_cluster.example.engine_version
  identifier                = "test-primary-cluster-instance"
  cluster_identifier        = aws_neptune_cluster.primary.id
  instance_class            = "db.r5.large"
  neptune_subnet_group_name = "default"
}

resource "aws_neptune_cluster" "secondary" {
  provider                  = aws.secondary
  engine                    = aws_neptune_global_cluster.example.engine
  engine_version            = aws_neptune_global_cluster.example.engine_version
  cluster_identifier        = "test-secondary-cluster"
  global_cluster_identifier = aws_neptune_global_cluster.example.id
  neptune_subnet_group_name = "default"
}

resource "aws_neptune_cluster_instance" "secondary" {
  provider                  = aws.secondary
  engine                    = aws_neptune_global_cluster.example.engine
  engine_version            = aws_neptune_global_cluster.example.engine_version
  identifier                = "test-secondary-cluster-instance"
  cluster_identifier        = aws_neptune_cluster.secondary.id
  instance_class            = "db.r5.large"
  neptune_subnet_group_name = "default"

  depends_on = [
    aws_neptune_cluster_instance.primary
  ]
}

Debug Output

Official terraform code for creating global cluster is failing with below error. Global cluster and primary cluster and its instance getting created fine, but when terraform is trying to create secondary cluster, it is throwing below error.

Seems when terraform is trying to create secondary cluster, primary cluster is not in available or in state which is require for replication cluster.

Error: creating Neptune Cluster: InvalidDBClusterStateFault: Source cluster: arn:aws:rds:us-west-2:755529035501:cluster:test-neptune-db is in a state which is not valid for physical replication
│   status code: 400, request id: 9ca474fa-4892-4fab-8df5-6c2487403cff
│ 
│   with module.neptunedb.aws_neptune_cluster.secondary[0],
│   on neptune1/main.tf line 63, in resource "aws_neptune_cluster" "secondary":
│   63: resource "aws_neptune_cluster" "secondary" {

Expected Behavior

When you run terraform apply again, it works fine but it should work in one go.

Actual Behavior

when you run terraform apply it throws error.

I got a workaround that works fine in one go but that is not expected way of doing.

Steps to Reproduce

terraform init terraform apply

Additional Context

No response

References

No response

jbardin commented 1 year ago

Hello,

This appears to be an issue or question with the AWS provider, not with Terraform itself. You can see existing issues and file a new one in their repository here: https://github.com/hashicorp/terraform-provider-aws/issues. If you have questions about Terraform or the AWS provider, it's better to use the community forum where there are more people ready to help. The GitHub issues here are monitored only by a few core maintainers.

Thanks!

afaqueahmad commented 1 year ago

Thanks @jbardin, It make sense to me, let me raise this to aws provider.

github-actions[bot] commented 1 year ago

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.