Skip to content

Commit

Permalink
Allow google.project.id for passing project to resource_project_servi…
Browse files Browse the repository at this point in the history
…ce (#3975) (#7255)

* Alow project.id for passing project to resource_project_service

* remove adjustProjectReference and utilize GetResourceNameFromSelfLink

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 11, 2020
1 parent dd49958 commit 960ce26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .changelog/3975.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
project_service: Added ability to pass google.project.id to project property
```
17 changes: 9 additions & 8 deletions google/resource_google_project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ func resourceGoogleProjectService() *schema.Resource {
ValidateFunc: StringNotInSlice(append(ignoredProjectServices, bannedProjectServices...), false),
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: compareResourceNames,
},

"disable_dependent_services": {
Expand Down Expand Up @@ -119,12 +120,10 @@ func resourceGoogleProjectServiceCreate(d *schema.ResourceData, meta interface{}
if err != nil {
return err
}
project = GetResourceNameFromSelfLink(project)

srv := d.Get("service").(string)
id, err := replaceVars(d, config, "{{project}}/{{service}}")
if err != nil {
return fmt.Errorf("unable to construct ID: %s", err)
}
id := project + "/" + srv

// Check if the service has already been enabled
servicesRaw, err := BatchRequestReadServices(project, d, config)
Expand Down Expand Up @@ -155,6 +154,7 @@ func resourceGoogleProjectServiceRead(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}
project = GetResourceNameFromSelfLink(project)

// Verify project for services still exists
projectGetCall := config.clientResourceManager.Projects.Get(project)
Expand Down Expand Up @@ -206,6 +206,7 @@ func resourceGoogleProjectServiceDelete(d *schema.ResourceData, meta interface{}
if err != nil {
return err
}
project = GetResourceNameFromSelfLink(project)

service := d.Get("service").(string)
disableDependencies := d.Get("disable_dependent_services").(bool)
Expand Down
6 changes: 3 additions & 3 deletions google/resource_google_project_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccProjectService_basic(t *testing.T) {
ResourceName: "google_project_service.test2",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"disable_on_destroy"},
ImportStateVerifyIgnore: []string{"disable_on_destroy", "project"},
},
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
{
Expand Down Expand Up @@ -189,7 +189,7 @@ func testAccProjectService_basic(services []string, pid, name, org string) strin
return fmt.Sprintf(`
provider "google" {
user_project_override = true
}
}
resource "google_project" "acceptance" {
project_id = "%s"
name = "%s"
Expand All @@ -202,7 +202,7 @@ resource "google_project_service" "test" {
}
resource "google_project_service" "test2" {
project = google_project.acceptance.project_id
project = google_project.acceptance.id
service = "%s"
}
`, pid, name, org, services[0], services[1])
Expand Down

0 comments on commit 960ce26

Please sign in to comment.