Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow brand new setup for google_developer_connect_connection #8953

Merged
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
3 changes: 3 additions & 0 deletions .changelog/12493.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
developerconnect: added support for setting up a brand new `google_developer_connect_connection`
```
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ Possible values:
},
"app_installation_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `Optional. GitHub App installation id.`,
},
"authorizer_credential": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `Represents an OAuth token of the account that authorized the Connection,and
associated metadata.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ import (
"github.com/hashicorp/terraform-plugin-testing/terraform"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func TestAccDeveloperConnectConnection_developerConnectConnectionBasicExample(t *testing.T) {
func TestAccDeveloperConnectConnection_developerConnectConnectionNewExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project": envvar.GetTestProjectFromEnv(),
"random_suffix": acctest.RandString(t, 10),
}

Expand All @@ -43,7 +45,7 @@ func TestAccDeveloperConnectConnection_developerConnectConnectionBasicExample(t
CheckDestroy: testAccCheckDeveloperConnectConnectionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDeveloperConnectConnection_developerConnectConnectionBasicExample(context),
Config: testAccDeveloperConnectConnection_developerConnectConnectionNewExample(context),
},
{
ResourceName: "google_developer_connect_connection.my-connection",
Expand All @@ -55,21 +57,88 @@ func TestAccDeveloperConnectConnection_developerConnectConnectionBasicExample(t
})
}

func testAccDeveloperConnectConnection_developerConnectConnectionBasicExample(context map[string]interface{}) string {
func testAccDeveloperConnectConnection_developerConnectConnectionNewExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_developer_connect_connection" "my-connection" {
provider = google-beta
location = "us-central1"
connection_id = "tf-test-tf-test-connection%{random_suffix}"
connection_id = "tf-test-tf-test-connection-new%{random_suffix}"

github_config {
github_app = "FIREBASE"
}

depends_on = [google_project_iam_member.devconnect-secret]
}

output "next_steps" {
description = "Follow the action_uri if present to continue setup"
value = google_developer_connect_connection.my-connection.installation_state
}

# Setup permissions. Only needed once per project
resource "google_project_service_identity" "devconnect-p4sa" {
provider = google-beta

service = "developerconnect.googleapis.com"
}

resource "google_project_iam_member" "devconnect-secret" {
provider = google-beta

project = "%{project}"
role = "roles/secretmanager.admin"
member = google_project_service_identity.devconnect-p4sa.member
}
`, context)
}

func TestAccDeveloperConnectConnection_developerConnectConnectionExistingCredentialsExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"secret_name": "projects/devconnect-terraform-creds/secrets/tf-test-do-not-change-github-oauthtoken-e0b9e7/versions/1",
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckDeveloperConnectConnectionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDeveloperConnectConnection_developerConnectConnectionExistingCredentialsExample(context),
},
{
ResourceName: "google_developer_connect_connection.my-connection",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "connection_id", "labels", "location", "terraform_labels"},
},
},
})
}

func testAccDeveloperConnectConnection_developerConnectConnectionExistingCredentialsExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_developer_connect_connection" "my-connection" {
provider = google-beta
location = "us-central1"
connection_id = "tf-test-tf-test-connection-cred%{random_suffix}"

github_config {
github_app = "DEVELOPER_CONNECT"

authorizer_credential {
oauth_token_secret_version = "projects/devconnect-terraform-creds/secrets/tf-test-do-not-change-github-oauthtoken-e0b9e7/versions/1"
oauth_token_secret_version = "%{secret_name}"
}
}
}

output "next_steps" {
description = "Follow the action_uri if present to continue setup"
value = google_developer_connect_connection.my-connection.installation_state
}
`, context)
}

Expand Down
59 changes: 53 additions & 6 deletions website/docs/r/developer_connect_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,71 @@ A connection to a GitHub App installation.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.


## Example Usage - Developer Connect Connection New


```hcl
resource "google_developer_connect_connection" "my-connection" {
provider = google-beta
location = "us-central1"
connection_id = "tf-test-connection-new"
github_config {
github_app = "FIREBASE"
}
depends_on = [google_project_iam_member.devconnect-secret]
}
output "next_steps" {
description = "Follow the action_uri if present to continue setup"
value = google_developer_connect_connection.my-connection.installation_state
}
# Setup permissions. Only needed once per project
resource "google_project_service_identity" "devconnect-p4sa" {
provider = google-beta
service = "developerconnect.googleapis.com"
}
resource "google_project_iam_member" "devconnect-secret" {
provider = google-beta
project = "my-project-name"
role = "roles/secretmanager.admin"
member = google_project_service_identity.devconnect-p4sa.member
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=developer_connect_connection_basic&open_in_editor=main.tf" target="_blank">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=developer_connect_connection_existing_credentials&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Developer Connect Connection Basic
## Example Usage - Developer Connect Connection Existing Credentials


```hcl
resource "google_developer_connect_connection" "my-connection" {
provider = google-beta
location = "us-central1"
connection_id = "tf-test-connection"
connection_id = "tf-test-connection-cred"
github_config {
github_app = "DEVELOPER_CONNECT"
authorizer_credential {
oauth_token_secret_version = "projects/devconnect-terraform-creds/secrets/tf-test-do-not-change-github-oauthtoken-e0b9e7/versions/1"
oauth_token_secret_version = "projects/your-project/secrets/your-secret-id/versions/latest"
}
}
}
output "next_steps" {
description = "Follow the action_uri if present to continue setup"
value = google_developer_connect_connection.my-connection.installation_state
}
```
## Example Usage - Developer Connect Connection Github Doc
## Example Usage - Developer Connect Connection Existing Installation


```hcl
Expand All @@ -69,11 +110,17 @@ resource "google_secret_manager_secret_version" "github-token-secret-version" {
secret_data = file("my-github-token.txt")
}
resource "google_project_service_identity" "devconnect-p4sa" {
provider = google-beta
service = "developerconnect.googleapis.com"
}
data "google_iam_policy" "p4sa-secretAccessor" {
binding {
role = "roles/secretmanager.secretAccessor"
// Here, 123456789 is the Google Cloud project number for the project that contains the connection.
members = ["serviceAccount:service-123456789@gcp-sa-devconnect.iam.gserviceaccount.com"]
members = [google_project_service_identity.devconnect-p4sa.member]
}
}
Expand Down
Loading