Closed hb9cwp closed 2 years ago
With simple example.tf
below, and an app that was launched by flyctl before (e.g. outside of Terraform), just do:
$ export FLY_TOKEN=$(fly auth token)
$ terraform init
$ terraform validate
$ terraform plan
$ terraform apply
...
terraform {
required_providers {
fly = {
#source = "dov.dev/fly/fly-provider"
source = "DAlperin/fly-io"
version = "0.0.4"
}
}
}
provider "fly" {
# Don't do this:
#flytoken = "abc123" # If not set checks env for FLY_TOKEN
# But do:
# $ export FLY_TOKEN=$(fly auth token)
}
data "fly_app" "exampleApp" {
# https://registry.terraform.io/providers/DAlperin/fly-io/latest/docs/data-sources/app
name = "https-helloworld-11"
#depends_on = [fly_app.exampleApp] <=== Data does not depend on any (imported) Resources!
}
output "Data_app" {
value = data.fly_app.exampleApp
}
output "Data_app_IPaddrs" {
value = data.fly_app.exampleApp.ipaddresses
}
data "fly_cert" "exampleCert" {
# https://registry.terraform.io/providers/DAlperin/fly-io/latest/docs/data-sources/cert
app = "https-helloworld-11"
hostname = "flyhelloword.a0t.ch"
}
output "Data_cert" {
value = data.fly_cert.exampleCert
}
output "Data_cert_check" {
value = data.fly_cert.exampleCert.check
}
Yeahhhh sorry about that. This is on the list. Will be fixed soon
But in your particular example I have a rationale:
Data source fly_app expects name as input, whereas fly_cert and fly_ip both expect app for the same thing.
I use app
for fly_ip and fly_cert because they belong to an app
. For fly_app I use name since I am not referencing an existing app, I am naming this new resource. Might be to complicated though, let me know what you think.
Ok, this makes sense, thanks.
Data source
fly_app
expectsname
as input, whereasfly_cert
andfly_ip
both expectapp
for the same thing. All do accept an application name. But, I have not tried with their ID yet, in case they are treated interchangeably.