https://pulumi.com logo
#typescript
Title
# typescript
l

little-cartoon-10569

12/11/2020, 1:24 AM
What is the recommended way to import types?
In my test code, I want to check some fields in an aws.backup.Plan's rules property. The type is
input/backup/PlanRule[]
I'm currently using
import {input} from "@pulumi/aws/types"
and then I can use
input.backup.PlanRule
.
Is that the right way to do it? Is there a shorter way, or a way to make it look like
aws.backup.PlanRule
, or...?
c

cool-fireman-90027

12/11/2020, 2:00 PM
Is this what you are looking for?
Copy code
import * as aws from "@pulumi/aws";

const myplan = new aws.backup.Plan("shaht-backupplan", {
    name: "shahtbackupplan",
    rules: [{
        ruleName: "tf_example_backup_rule",
        targetVaultName: "Default",
        schedule: "cron(0 12 * * ? *)",
    }],
    advancedBackupSettings: [{
        backupOptions: {
            WindowsVSS: "enabled",
        },
        resourceType: "EC2",
    }],
});

export const backup_plan_name = myplan.name;
export const backup_plan_version = myplan.version;
export const backup_plan_rules = myplan.rules;
export const backup_plan_lifecycle = myplan.rules[0]["lifecycle"];
export const backup_plan_completionWindow = myplan.rules[0]["completionWindow"];
export const backup_plan_schedule = myplan.rules[0]["schedule"];
The last 3 lines seem like the what you want to get at Here is my output of them:
backup_plan_completionWindow  180
backup_plan_lifecycle         null
backup_plan_schedule          cron(0 12 * * ? *)
l

little-cartoon-10569

12/13/2020, 8:27 PM
I want to use an object of type PlanRule, and strongly type it. I want to be able to do something like
const rule: aws.backup.PlanRule = plan.rules[0];
I expected to be use
aws.backup.PlanRule
, since that's where everything else is, but instead I'm having to use
input.backup.PlanRule
. I just wanted to know if that's expected and I'm doing it correctly, or if there's a different (better) way to do it.
2 Views