github.com/mcuadros/ascode@v1.3.1/starlark/types/testdata/attribute.star (about) 1 load("assert.star", "assert") 2 3 aws = tf.provider("aws", "2.13.0") 4 5 ami = aws.data.ami() 6 7 # attribute of scalar 8 web = aws.resource.instance() 9 web.ami = ami.id 10 assert.eq(type(web.ami), "Attribute<string>") 11 assert.eq(str(web.ami), "${data.aws_ami.id_2.id}") 12 assert.eq(web.ami.__resource__, ami) 13 assert.eq(web.ami.__type__, "string") 14 15 # attr names 16 assert.eq("__resource__" in dir(web.ami), True) 17 assert.eq("__type__" in dir(web.ami), True) 18 19 # attribute of set 20 table = aws.data.dynamodb_table() 21 assert.eq(str(table.ttl), "${data.aws_dynamodb_table.id_4.ttl}") 22 assert.eq(str(table.ttl[0]), "${data.aws_dynamodb_table.id_4.ttl.0}") 23 assert.eq(str(table.ttl[0].attribute_name), "${data.aws_dynamodb_table.id_4.ttl.0.attribute_name}") 24 25 # attribute of list 26 instance = aws.data.instance() 27 assert.eq(str(instance.credit_specification), "${data.aws_instance.id_5.credit_specification}") 28 assert.eq(str(instance.credit_specification[0]), "${data.aws_instance.id_5.credit_specification.0}") 29 assert.eq(str(instance.credit_specification[0].cpu_credits), "${data.aws_instance.id_5.credit_specification.0.cpu_credits}") 30 31 # attribute of block 32 attribute = str(aws.resource.instance().root_block_device.volume_size) 33 assert.eq(attribute, "${aws_instance.id_6.root_block_device.0.volume_size}") 34 35 # attribute on data source 36 assert.eq(str(aws.resource.instance().id), "${aws_instance.id_7.id}") 37 38 # attribute on resource 39 assert.eq(str(aws.data.ami().id), "${data.aws_ami.id_8.id}") 40 41 gcp = tf.provider("google", "3.13.0") 42 43 # attribute on list with MaxItem:1 44 cluster = gcp.resource.container_cluster("foo") 45 assert.eq(str(cluster.master_auth.client_certificate), "${google_container_cluster.foo.master_auth.0.client_certificate}") 46 47 # attr non-object 48 assert.fails(lambda: web.ami.foo, "Attribute<string> it's not a object") 49 50 # fn wrapping 51 assert.eq(str(fn("base64encode", web.ami)), "${base64encode(data.aws_ami.id_2.id)}") 52 53 # attribute of dict 54 k8s = tf.provider("kubernetes") 55 56 secret = k8s.data.secret("foo") 57 assert.eq(str(secret.data["qux"]), "${data.kubernetes_secret.foo.data.qux}") 58 assert.eq(str(secret.data["qux"][0]), "${data.kubernetes_secret.foo.data.qux.0}") 59 60 # ref 61 secret = k8s.resource.secret("foo") 62 secret.metadata.name = "foo" 63 secret.type = "kubernetes.io/dockerconfigjson" 64 assert.eq(str(ref(secret, "type")), "${kubernetes_secret.foo.type}") 65 assert.eq(str(ref(secret.metadata, "name")), "${kubernetes_secret.foo.metadata.0.name}") 66 67 # ref to non-exits 68 assert.fails(lambda: ref(secret, "foo"), "Resource<kubernetes.resource.kubernetes_secret> has no .foo field")