Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apigee
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -140,6 +141,23 @@ func resourceApigeeSharedflowDeploymentRead(d *schema.ResourceData, meta interfa
}
log.Printf("[DEBUG] ApigeeSharedflowDeployment deployStartTime %s", res["deployStartTime"])

// org_id is not returned by the API; it is derived from the resource ID
// (set by Create or by the import parser) and stays in state untouched.
if err := d.Set("environment", flattenApigeeSharedflowDeploymentEnvironment(res["environment"], d, config)); err != nil {
return fmt.Errorf("Error reading SharedflowDeployment: %s", err)
}
// The API uses `apiProxy` for both API proxy and shared flow deployments
// to identify the deployed artifact.
if err := d.Set("sharedflow_id", flattenApigeeSharedflowDeploymentSharedflowId(res["apiProxy"], d, config)); err != nil {
return fmt.Errorf("Error reading SharedflowDeployment: %s", err)
}
if err := d.Set("revision", flattenApigeeSharedflowDeploymentRevision(res["revision"], d, config)); err != nil {
return fmt.Errorf("Error reading SharedflowDeployment: %s", err)
}
if err := d.Set("service_account", flattenApigeeSharedflowDeploymentServiceAccount(res["serviceAccount"], d, config)); err != nil {
return fmt.Errorf("Error reading SharedflowDeployment: %s", err)
}

return nil
}

Expand Down Expand Up @@ -263,7 +281,19 @@ func flattenApigeeSharedflowDeploymentRevision(v interface{}, d *schema.Resource
}

func flattenApigeeSharedflowDeploymentServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
// The Apigee API may return service accounts as a full resource name
// (e.g. "projects/-/serviceAccounts/sa@project.iam.gserviceaccount.com")
// while the schema documents (and Create accepts) the bare email form.
// Strip the prefix when present so a Read after a Create using the bare
// email does not show drift.
if v == nil {
return v
}
s, ok := v.(string)
if !ok {
return v
}
return strings.TrimPrefix(s, "projects/-/serviceAccounts/")
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,18 @@ resource "google_apigee_sharedflow" "test_apigee_sharedflow" {
depends_on = [google_apigee_organization.apigee_org]
}

resource "google_service_account" "sharedflow_sa" {
account_id = "tf-test-sf-sa%{random_suffix}"
display_name = "TF Test Sharedflow SA"
project = google_project.project.project_id
}

resource "google_apigee_sharedflow_deployment" "sharedflow_deployment_test" {
environment = google_apigee_environment.apigee_environment.name
org_id = google_apigee_sharedflow.test_apigee_sharedflow.org_id
revision = google_apigee_sharedflow.test_apigee_sharedflow.revision[length(google_apigee_sharedflow.test_apigee_sharedflow.revision)-1]
sharedflow_id = google_apigee_sharedflow.test_apigee_sharedflow.name
environment = google_apigee_environment.apigee_environment.name
org_id = google_apigee_sharedflow.test_apigee_sharedflow.org_id
revision = google_apigee_sharedflow.test_apigee_sharedflow.revision[length(google_apigee_sharedflow.test_apigee_sharedflow.revision)-1]
sharedflow_id = google_apigee_sharedflow.test_apigee_sharedflow.name
service_account = google_service_account.sharedflow_sa.email
}
`, context)
}
Expand Down
Loading