forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blueprint_published_version_data_source.go
129 lines (104 loc) · 3.18 KB
/
blueprint_published_version_data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package blueprints
import (
"fmt"
"time"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
mgValidate "github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/managementgroup/validate"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/validation"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/timeouts"
"github.com/kevinklinger/terraform-provider-azurerm/v2/utils"
)
func dataSourceBlueprintPublishedVersion() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceBlueprintPublishedVersionRead,
Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*pluginsdk.Schema{
"blueprint_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"scope_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.Any(
azure.ValidateResourceID,
mgValidate.ManagementGroupID,
),
},
"version": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
// Computed
"description": {
Type: pluginsdk.TypeString,
Computed: true,
},
"display_name": {
Type: pluginsdk.TypeString,
Computed: true,
},
"last_modified": {
Type: pluginsdk.TypeString,
Computed: true,
},
"target_scope": {
Type: pluginsdk.TypeString,
Computed: true,
},
"time_created": {
Type: pluginsdk.TypeString,
Computed: true,
},
"type": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
func dataSourceBlueprintPublishedVersionRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Blueprints.PublishedBlueprintsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
scope := d.Get("scope_id").(string)
blueprintName := d.Get("blueprint_name").(string)
versionID := d.Get("version").(string)
resp, err := client.Get(ctx, scope, blueprintName, versionID)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Published Blueprint Version %q not found: %+v", versionID, err)
}
return fmt.Errorf("Read failed for Published Blueprint (%q) Version (%q): %+v", blueprintName, versionID, err)
}
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Failed to retrieve ID for Blueprint %q Version %q", blueprintName, versionID)
} else {
d.SetId(*resp.ID)
}
if resp.Type != nil {
d.Set("type", resp.Type)
}
if resp.Status != nil {
if resp.Status.TimeCreated != nil {
d.Set("time_created", resp.Status.TimeCreated.String())
}
if resp.Status.LastModified != nil {
d.Set("last_modified", resp.Status.LastModified.String())
}
}
d.Set("target_scope", resp.TargetScope)
if resp.DisplayName != nil {
d.Set("display_name", resp.DisplayName)
}
if resp.Description != nil {
d.Set("description", resp.Description)
}
return nil
}