Skip to content

Commit 7ffa212

Browse files
Add additional fields to projects data source (#3868) (#2440)
Signed-off-by: Modular Magician <[email protected]>
1 parent d5ec235 commit 7ffa212

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

.changelog/3868.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource-manager: added additional fields to `google_projects` datasource
3+
```

google-beta/data_source_google_projects.go

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ func dataSourceGoogleProjects() *schema.Resource {
2323
Type: schema.TypeString,
2424
Computed: true,
2525
},
26+
"create_time": {
27+
Type: schema.TypeString,
28+
Computed: true,
29+
},
30+
"labels": {
31+
Type: schema.TypeMap,
32+
Computed: true,
33+
Elem: &schema.Schema{Type: schema.TypeString},
34+
Description: `A set of key/value label pairs assigned on a project.`,
35+
},
36+
"parent": {
37+
Type: schema.TypeMap,
38+
Computed: true,
39+
Elem: &schema.Schema{Type: schema.TypeString},
40+
Description: `An optional reference to a parent Resource.`,
41+
},
42+
"number": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
Description: `The numeric identifier of the project.`,
46+
},
47+
"lifecycle_state": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
Description: `The numeric identifier of the project.`,
51+
},
52+
"name": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
Description: `The optional user-assigned display name of the Project.`,
56+
},
2657
},
2758
},
2859
},
@@ -79,11 +110,38 @@ func flattenDatasourceGoogleProjectsList(v interface{}) []map[string]interface{}
79110
projects := make([]map[string]interface{}, 0, len(ls))
80111
for _, raw := range ls {
81112
p := raw.(map[string]interface{})
113+
114+
var mId, mNumber, mLabels, mLifecycleState, mName, mCreateTime, mParent interface{}
82115
if pId, ok := p["projectId"]; ok {
83-
projects = append(projects, map[string]interface{}{
84-
"project_id": pId,
85-
})
116+
mId = pId
117+
}
118+
if pNumber, ok := p["projectNumber"]; ok {
119+
mNumber = pNumber
120+
}
121+
if pName, ok := p["name"]; ok {
122+
mName = pName
123+
}
124+
if pLabels, ok := p["labels"]; ok {
125+
mLabels = pLabels
126+
}
127+
if pLifecycleState, ok := p["lifecycleState"]; ok {
128+
mLifecycleState = pLifecycleState
129+
}
130+
if pCreateTime, ok := p["createTime"]; ok {
131+
mCreateTime = pCreateTime
132+
}
133+
if pParent, ok := p["parent"]; ok {
134+
mParent = pParent
86135
}
136+
projects = append(projects, map[string]interface{}{
137+
"project_id": mId,
138+
"number": mNumber,
139+
"name": mName,
140+
"labels": mLabels,
141+
"lifecycle_state": mLifecycleState,
142+
"create_time": mCreateTime,
143+
"parent": mParent,
144+
})
87145
}
88146

89147
return projects

google-beta/data_source_google_projects_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func TestAccDataSourceGoogleProjects_basic(t *testing.T) {
2121
Check: resource.ComposeTestCheckFunc(
2222
// We can't guarantee no project won't have our project ID as a prefix, so we'll check set-ness rather than correctness
2323
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.project_id"),
24+
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.name"),
25+
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.number"),
26+
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.lifecycle_state"),
27+
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.parent.id"),
28+
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.parent.type"),
29+
resource.TestCheckResourceAttrSet("data.google_projects.my-project", "projects.0.create_time"),
2430
),
2531
},
2632
},

0 commit comments

Comments
 (0)