-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add resources to validate a domain #5698
Comments
Similar issue was closed before: #1724 But I think it would be a good addition to this provider! In the meantime, you can use this: https://github.com/hectorj/terraform-provider-googlesiteverification Edit: I'm interested in trying to contribute it to this repo. I'll take a shot at it soon-ish. |
@danawillow @hectorj and I are perfectly willing to assist in providing the required resources. If you feel it can be auto-generated, then that would be awesome. I do think it needs some work as the API is not orthogonal. ie. the create and update have a different signature. |
If you already have handwritten code for the resource, then it's not mandatory to do it generated, especially if it's unusual. The one thing I would be very careful about is authentication- our guideline right now is that you should be able to use the same authentication method for all your resources, and based on #1724 (comment) I'm not 100% sure you can. |
@hectorj actually programmed it to work properly; if you look at the code at https://github.com/hectorj/terraform-provider-googlesiteverification, you can specify JSON service account key to authenticate with and that works. the site verification API did not work with the default Oauth 2.0 credentials, I actually created a separate service account to verify the domain with. See:
So this issue can be documented or even resolved in the resource definition. |
This is absolutely required from an automation stand point and I am actually incredulous that this isn't standard in the provider or that the APIs aren't set up in such a way at GCP. The above module doesn't work (at least not with latest versions of Terraform) and there is no documentation - please get this supported in the provider asap |
At 2 years old and 44 upvotes, is there any progress on this or plans to add it? This totally breaks automation when creating GCS buckets. I managed to create a workaround which manually invokes the site verification APIs through variable "project_id" { type = string }
variable "dns_name" { type = string }
variable "managed_dns_zone" { type = string }
variable "service_account_email" { type = string }
// Create an access token.
data "google_service_account_access_token" "verification" {
provider = google
target_service_account = "${var.service_account_email}"
scopes = ["https://www.googleapis.com/auth/siteverification", "https://www.googleapis.com/auth/siteverification.verify_only"]
lifetime = "2s"
}
// Invokes the Site Verification API to get a token.
// https://developers.google.com/site-verification/v1/invoking#verify
data "http" "api_verification" {
url = "https://www.googleapis.com/siteVerification/v1/token?access_token=${data.google_service_account_access_token.verification.access_token}"
method = "POST"
request_body = <<EOT
{
"verificationMethod": "DNS_TXT",
"site": {
"identifier": "${var.dns_name}",
"type": "INET_DOMAIN"
}
}
EOT
# Optional request headers
request_headers = {
Content-Type = "application/json"
}
lifecycle {
postcondition {
condition = contains([201, 204, 200], self.status_code)
error_message = self.body
}
}
depends_on = [
data.google_service_account_access_token.verification
]
}
// Domain verification for static storage url.
resource "google_dns_record_set" "storage_static_verification" {
project = var.project_id
name = var.dns_name
type = "TXT"
ttl = 300
managed_zone = var.managed_dns_zone
rrdatas = [jsondecode(data.http.api_verification.response_body)["token"]]
depends_on = [data.http.api_verification]
}
data "google_service_account_access_token" "verification_confirm" {
provider = google
target_service_account = "${var.service_account_email}"
scopes = ["https://www.googleapis.com/auth/siteverification", "https://www.googleapis.com/auth/siteverification.verify_only"]
lifetime = "2s"
}
// From https://developers.google.com/site-verification/v1/invoking#exampleInsert
data "http" "api_verification_insert" {
url = "https://www.googleapis.com/siteVerification/v1/webResource?verificationMethod=DNS_TXT&access_token=${data.google_service_account_access_token.verification_confirm.access_token}"
method = "POST"
request_body = <<EOT
{
"site": {
"identifier": "${var.dns_name}",
"type": "INET_DOMAIN"
}
}
EOT
request_headers = {
Content-Type = "application/json"
}
lifecycle {
postcondition {
condition = contains([201, 204, 200], self.status_code)
error_message = self.body
}
}
depends_on = [
data.google_service_account_access_token.verification_confirm
]
} |
Any chance this could be added ? Ideally with OpenID Connect as the authentication method. |
I was able to confirm that this API can use the same OAuth 2.0 credentials that the Terraform provider operates on, so this seems like it would make sense in the |
👋 |
We are also facing the same issue currently - a fix would be much apppreciated |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Note for future readers of this issue: this is now implemented. |
Community Note
Description
Several operations on Google Cloud require you to validate domain ownership.
For example, creating a GCS bucket for static website hosting.
This is the usecase I met and the only one I know of, I suppose however there should be other affected resources.
There are currently no terraform resources for automating the validation process, nor to delegate domain ownership to a service account, which has several implications :
TL;DR : a lot of friction and manual work no matter what you do.
There is an API for automating site verification.
I don't know if it can be used when authenticated as a service account, but even if not, being able to automate this would be a great step forward.
New or Affected Resource(s)
AWS have several resources requiring similar validation processes, my API proposal is based on the one used by aws_ses_domain_identity_verification
Potential Terraform Configuration
References
Relevant documentation was referenced above
The text was updated successfully, but these errors were encountered: