Skip to content

Commit

Permalink
Wait for first_recoverability_time in Terraform test (#65)
Browse files Browse the repository at this point in the history
* Wait for `first_recoverability_time` in Terraform test

* WIP add first_recoverability_time to Instance model

* Check if `FirstRecoverabilityTime` is set but nil

* Force a 6 min wait time during acceptance test

* Remove unused testCheckFirstRecoverabilityTimeSet function

* `go generate`
  • Loading branch information
vrmiguel authored Aug 20, 2024
1 parent a516b96 commit 2a60969
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ output "instance" {
- `connection_pooler` (Attributes) (see [below for nested schema](#nestedatt--connection_pooler))
- `extensions` (Attributes List) Extensions to install in the instance (see [below for nested schema](#nestedatt--extensions))
- `extra_domains_rw` (List of String) Custom domain. Read more [here](https://tembo.io/docs/tembo-cloud/custom-domains/)
- `first_recoverability_time` (String) The time at which the instance first became recoverable
- `ip_allow_list` (List of String) Allowed IP list
- `postgres_configs` (Attributes List) Postgres configs (see [below for nested schema](#nestedatt--postgres_configs))
- `replicas` (Number) Instance replicas
Expand Down
49 changes: 31 additions & 18 deletions internal/provider/instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@ const (

// temboInstanceResourceModel maps the resource schema data.
type temboInstanceResourceModel struct {
InstanceID types.String `tfsdk:"instance_id"`
InstanceName types.String `tfsdk:"instance_name"`
OrgId types.String `tfsdk:"org_id"`
CPU types.String `tfsdk:"cpu"`
StackType types.String `tfsdk:"stack_type"`
Environment types.String `tfsdk:"environment"`
Replicas types.Int64 `tfsdk:"replicas"`
Memory types.String `tfsdk:"memory"`
Storage types.String `tfsdk:"storage"`
LastUpdated types.String `tfsdk:"last_updated"`
State types.String `tfsdk:"state"`
ExtraDomainsRw []types.String `tfsdk:"extra_domains_rw"`
PostgresConfigs []KeyValue `tfsdk:"postgres_configs"`
TrunkInstalls []TrunkInstall `tfsdk:"trunk_installs"`
Extensions []Extension `tfsdk:"extensions"`
IpAllowList []types.String `tfsdk:"ip_allow_list"`
ConnectionPooler *ConnectionPooler `tfsdk:"connection_pooler"`
Restore *Restore `tfsdk:"restore"`
InstanceID types.String `tfsdk:"instance_id"`
InstanceName types.String `tfsdk:"instance_name"`
OrgId types.String `tfsdk:"org_id"`
CPU types.String `tfsdk:"cpu"`
StackType types.String `tfsdk:"stack_type"`
Environment types.String `tfsdk:"environment"`
Replicas types.Int64 `tfsdk:"replicas"`
Memory types.String `tfsdk:"memory"`
Storage types.String `tfsdk:"storage"`
LastUpdated types.String `tfsdk:"last_updated"`
State types.String `tfsdk:"state"`
ExtraDomainsRw []types.String `tfsdk:"extra_domains_rw"`
PostgresConfigs []KeyValue `tfsdk:"postgres_configs"`
TrunkInstalls []TrunkInstall `tfsdk:"trunk_installs"`
Extensions []Extension `tfsdk:"extensions"`
IpAllowList []types.String `tfsdk:"ip_allow_list"`
ConnectionPooler *ConnectionPooler `tfsdk:"connection_pooler"`
Restore *Restore `tfsdk:"restore"`
FirstRecoverabilityTime types.String `tfsdk:"first_recoverability_time"`
}

type Restore struct {
Expand Down Expand Up @@ -309,6 +310,11 @@ func (r *temboInstanceResource) Schema(_ context.Context, _ resource.SchemaReque
},
Optional: true,
},
"first_recoverability_time": schema.StringAttribute{
Computed: true,
Optional: true,
Description: "The time at which the instance first became recoverable",
},
},
}
}
Expand Down Expand Up @@ -716,6 +722,13 @@ func setTemboInstanceResourceModel(instanceResourceModel *temboInstanceResourceM
}
instanceResourceModel.IpAllowList = localIpAllowList
}

if instance.FirstRecoverabilityTime.IsSet() && instance.FirstRecoverabilityTime.Get() != nil {
fmt.Println("Setting FirstRecoverabilityTime")
instanceResourceModel.FirstRecoverabilityTime = types.StringValue(instance.FirstRecoverabilityTime.Get().Format(time.RFC3339))
} else {
instanceResourceModel.FirstRecoverabilityTime = types.StringNull()
}
}

func getStringArray(inputArray []basetypes.StringValue) []string {
Expand Down
22 changes: 22 additions & 0 deletions internal/provider/instance_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ func TestTemboInstanceResource(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "connection_pooler.pooler.parameters.default_pool_size", "100"),
),
},
// Wait for 6 minutes to ensure that the initial backup has gone through
{
Config: testProviderConfig() + testInstanceResourceCreateConfig(instanceName, orgId),
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
fmt.Println("Waiting for 6 minutes before checking first_recoverability_time...")
time.Sleep(6 * time.Minute)
return nil
},
),
},
// Check that first_recoverability_time is set
{
Config: testProviderConfig() + testInstanceResourceCreateConfig(instanceName, orgId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "first_recoverability_time"),
func(s *terraform.State) error {
fmt.Println("first_recoverability_time has been set successfully")
return nil
},
),
},
// ImportState testing
{
ResourceName: resourceName,
Expand Down

0 comments on commit 2a60969

Please sign in to comment.