Skip to content

Commit

Permalink
RDS: Change status to 'available' to ensure TF works (#7749)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Jun 5, 2024
1 parent 8669dde commit 1190098
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests_terraform_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
service: ["acm", "awslambda", "cloudfront", "elb", "iam", "route53", "sqs"]
service: ["acm", "awslambda", "cloudfront", "elb", "iam", "rds", "route53", "sqs"]

steps:
- uses: actions/checkout@v4
Expand Down
19 changes: 11 additions & 8 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __init__(self, **kwargs: Any):
self.iops = kwargs.get("iops")
self.kms_key_id = kwargs.get("kms_key_id")
self.network_type = kwargs.get("network_type") or "IPV4"
self.status = "active"
self.status = "available"
self.account_id = kwargs.get("account_id")
self.region_name = kwargs["region"]
self.cluster_create_time = iso_8601_datetime_with_milliseconds()
Expand Down Expand Up @@ -192,7 +192,6 @@ def __init__(self, **kwargs: Any):
]
self.parameter_group = kwargs.get("parameter_group") or "default.aurora8.0"
self.subnet_group = kwargs.get("db_subnet_group_name") or "default"
self.status = "creating"
self.url_identifier = "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(12)
)
Expand All @@ -201,7 +200,9 @@ def __init__(self, **kwargs: Any):
self.port: int = kwargs.get("port") # type: ignore
if self.port is None:
self.port = Cluster.default_port(self.engine)
self.preferred_backup_window = "01:37-02:07"
self.preferred_backup_window = (
kwargs.get("preferred_backup_window") or "01:37-02:07"
)
self.preferred_maintenance_window = "wed:02:40-wed:03:10"
# This should default to the default security group
self.vpc_security_group_ids: List[str] = kwargs["vpc_security_group_ids"]
Expand Down Expand Up @@ -244,6 +245,7 @@ def __init__(self, **kwargs: Any):
self.global_write_forwarding_requested = kwargs.get(
"enable_global_write_forwarding"
)
self.backup_retention_period = kwargs.get("backup_retention_period") or 1

@property
def is_multi_az(self) -> bool:
Expand Down Expand Up @@ -317,7 +319,8 @@ def get_cfg(self) -> Dict[str, Any]:
cfg["enable_http_endpoint"] = cfg.pop("_enable_http_endpoint")
return cfg

def to_xml(self) -> str:
def to_xml(self, initial: bool = False) -> str:
status = "creating" if initial else self.status
template = Template(
"""<DBCluster>
<AllocatedStorage>{{ cluster.allocated_storage }}</AllocatedStorage>
Expand All @@ -326,7 +329,7 @@ def to_xml(self) -> str:
<AvailabilityZone>{{ zone }}</AvailabilityZone>
{% endfor %}
</AvailabilityZones>
<BackupRetentionPeriod>1</BackupRetentionPeriod>
<BackupRetentionPeriod>{{ cluster.backup_retention_period }}</BackupRetentionPeriod>
<BacktrackWindow>0</BacktrackWindow>
<DBInstanceStatus>{{ cluster.status }}</DBInstanceStatus>
{% if cluster.db_name %}<DatabaseName>{{ cluster.db_name }}</DatabaseName>{% endif %}
Expand All @@ -338,7 +341,7 @@ def to_xml(self) -> str:
<ClusterCreateTime>{{ cluster.cluster_create_time }}</ClusterCreateTime>
<EarliestRestorableTime>{{ cluster.earliest_restorable_time }}</EarliestRestorableTime>
<Engine>{{ cluster.engine }}</Engine>
<Status>{{ cluster.status }}</Status>
<Status>{{ status }}</Status>
<Endpoint>{{ cluster.endpoint }}</Endpoint>
<ReaderEndpoint>{{ cluster.reader_endpoint }}</ReaderEndpoint>
<MultiAZ>{{ 'true' if cluster.is_multi_az else 'false' }}</MultiAZ>
Expand Down Expand Up @@ -377,7 +380,7 @@ def to_xml(self) -> str:
</VpcSecurityGroups>
<HostedZoneId>{{ cluster.hosted_zone_id }}</HostedZoneId>
<StorageEncrypted>{{ 'true' if cluster.storage_encrypted else 'false' }}</StorageEncrypted>
<GlobalWriteForwardingRequested>{{ cluster.global_write_forwarding_requested }}</GlobalWriteForwardingRequested>
<GlobalWriteForwardingRequested>{{ 'true' if cluster.global_write_forwarding_requested else 'false' }}</GlobalWriteForwardingRequested>
<DbClusterResourceId>{{ cluster.resource_id }}</DbClusterResourceId>
<DBClusterArn>{{ cluster.db_cluster_arn }}</DBClusterArn>
<AssociatedRoles></AssociatedRoles>
Expand Down Expand Up @@ -423,7 +426,7 @@ def to_xml(self) -> str:
{%- if cluster.replication_source_identifier -%}<ReplicationSourceIdentifier>{{ cluster.replication_source_identifier }}</ReplicationSourceIdentifier>{%- endif -%}
</DBCluster>"""
)
return template.render(cluster=self)
return template.render(cluster=self, status=status)

@staticmethod
def default_engine_version(engine: str) -> str:
Expand Down
4 changes: 3 additions & 1 deletion moto/rds/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def _get_db_cluster_kwargs(self) -> Dict[str, Any]:
"vpc_security_group_ids": self.unpack_list_params(
"VpcSecurityGroupIds", "VpcSecurityGroupId"
),
"preferred_backup_window": self._get_param("PreferredBackupWindow"),
"backup_retention_period": self._get_param("BackupRetentionPeriod"),
}

def _get_export_task_kwargs(self) -> Dict[str, Any]:
Expand Down Expand Up @@ -1312,7 +1314,7 @@ def create_db_proxy(self) -> str:

CREATE_DB_CLUSTER_TEMPLATE = """<CreateDBClusterResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<CreateDBClusterResult>
{{ cluster.to_xml() }}
{{ cluster.to_xml(initial=True) }}
</CreateDBClusterResult>
<ResponseMetadata>
<RequestId>523e3218-afc7-11c3-90f5-f90431260ab4</RequestId>
Expand Down
14 changes: 14 additions & 0 deletions other_langs/terraform/rds/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
provider "aws" {
region = "us-east-1"
s3_use_path_style = true
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true

endpoints {
rds = "http://localhost:5000"
}

access_key = "my-access-key"
secret_key = "my-secret-key"
}
11 changes: 11 additions & 0 deletions other_langs/terraform/rds/rds.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_rds_cluster" "postgresql" {
cluster_identifier = "aurora-cluster-demo"
engine = "aurora-postgresql"
availability_zones = ["us-east-1a"]
database_name = "mydb"
master_username = "foo"
master_password = "barbarbar"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
skip_final_snapshot = true
}

0 comments on commit 1190098

Please sign in to comment.