Closed allanlegalstart closed 5 years ago
I’m not sure what @clintonb-stripe actually. I’ll let him chime in. I interpreted it as “you can set your resources active
” when I did the code review. Thanks!
The idea behind that line is that you could create resources with with you test API token and do your testing. Once your testing is complete, you can run the Terraform with your live API key. In hindsight, this is not well thought out on my part.
I am fine with removing that line from the README since it is not normal for Terraform users to change API keys, and a user would essentially need to maintain two copies of their Terraform configuration to avoid conflicts.
I’ll delete that line. Thanks for responding so promptly @clintonb-stripe !
I'm assuming live vs prod should be done using workspaces (providing different API keys when running in different workspaces), or is there another mechanism recommended to test out the changes before push to live?
Thanks
(sorry to dig up the old thread)
@slobo yes, using workspaces makes sense. That said, the functionality is new to me, and I have not tested it. Can you test this, and report back on whether it works?
👍 on what @clintonb-stripe just said. I'd also love to document how to use workspaces in the README/wiki because it definitely looks like something people may want to use. Thanks folks!
So this worked for me.
variable "stripe_api_token" {}
provider "stripe" {
api_token = "${var.stripe_api_token}"
}
resource "stripe_product" "my_product" {
name = "Test Product"
type = "service"
}
terraform init
terraform workplace select Testing || terraform workplace new Testing
terraform apply
# When prompted, enter the test token, ex. rk_test_XXXXXXXX
terraform init
terraform workplace select Live || terraform workplace new Live
terraform apply
# When prompted, enter the live token, ex. rk_live_YYYYYYY
Depending on your needs, you have options on automatically passing the API token to terraform apply
env TF_VAR_stripe_api_token=<TOKEN> terraform apply
-var stripe_api_token=<TOKEN>
-var-file=<Env.tfvars>
I tend to keep a copy of test token in a .tfvars file for developer convenience. But on the build server we provide live token via an environment variable. YMMV.
If you are collaborating with a team, make sure to store the state in some central location, say in an S3 bucket. Workspaces work with remote storage without problem.
This is great. Thanks @slobo!
@franckverrot should we update the README to state that the provider is compatible with workspaces?
Sorry, to digup this once again. Just wanted to note that I was able to solve this (IMO bit more elegantly) using provider aliases. It's as simple as this:
variable "stripe_test_secret_api_key" {}
provider "stripe" {
alias = "test"
api_token = var.stripe_test_secret_api_key
}
variable "stripe_live_secret_api_key" {}
provider "stripe" {
alias = "live"
api_token = var.stripe_live_secret_api_key
}
# A webhook in test mode
resource "stripe_webhook_endpoint" "my_webhook" {
# Use the test mode provider.
provider = stripe.test
...
}
# A webhook in live mode
resource "stripe_webhook_endpoint" "my_webhook" {
# Use the test mode provider.
provider = stripe.live
...
}
Hope this helps. .)
The readme says:
It would be great if the readme explained how to do this :)